Skip to content

Commit 1394d24

Browse files
committed
Fix #1933: Restrict value field to support number only
1 parent ce59ee9 commit 1394d24

File tree

1 file changed

+63
-0
lines changed

1 file changed

+63
-0
lines changed

app/Crud/UnitCrud.php

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
namespace App\Crud;
44

5+
use App\Classes\CrudForm;
6+
use App\Classes\FormInput;
57
use App\Models\Unit;
68
use App\Models\UnitGroup;
79
use App\Services\CrudEntry;
@@ -125,6 +127,67 @@ public function isEnabled( $feature ): bool
125127
*/
126128
public function getForm( $entry = null )
127129
{
130+
return CrudForm::form(
131+
main: FormInput::text(
132+
label: __( 'Name' ),
133+
name: 'name',
134+
value: $entry->name ?? '',
135+
description: __( 'Provide a name to the resource.' ),
136+
validation: 'required',
137+
),
138+
tabs: CrudForm::tabs(
139+
CrudForm::tab(
140+
identifier: 'general',
141+
label: __( 'General' ),
142+
fields: CrudForm::fields(
143+
FormInput::text(
144+
label: __( 'Identifier' ),
145+
name: 'identifier',
146+
description: __( 'Provide a unique value for this unit. Might be composed from a name but shouldn\'t include space or special characters.' ),
147+
validation: 'required|unique:' . Hook::filter( 'ns-table-name', 'nexopos_units' ) . ',identifier' . ( $entry !== null ? ',' . $entry->id : '' ),
148+
value: $entry->identifier ?? '',
149+
),
150+
FormInput::media(
151+
label: __( 'Preview URL' ),
152+
name: 'preview_url',
153+
description: __( 'Preview of the unit.' ),
154+
value: $entry->preview_url ?? '',
155+
),
156+
FormInput::text(
157+
label: __( 'Value' ),
158+
name: 'value',
159+
description: __( 'Define the value of the unit.' ),
160+
validation: 'required|numeric',
161+
value: $entry->value ?? '',
162+
),
163+
FormInput::searchSelect(
164+
component: 'nsCrudForm',
165+
props: UnitGroupCrud::getFormConfig(),
166+
name: 'group_id',
167+
validation: 'required',
168+
options: Helper::toJsOptions( UnitGroup::get(), [ 'id', 'name' ] ),
169+
label: __( 'Group' ),
170+
description: __( 'Define to which group the unit should be assigned.' ),
171+
value: $entry->group_id ?? '',
172+
),
173+
FormInput::switch(
174+
name: 'base_unit',
175+
validation: 'required',
176+
options: Helper::kvToJsOptions( [ __( 'No' ), __( 'Yes' ) ] ),
177+
label: __( 'Base Unit' ),
178+
description: __( 'Determine if the unit is the base unit from the group.' ),
179+
value: $entry ? ( $entry->base_unit ? 1 : 0 ) : 0,
180+
),
181+
FormInput::textarea(
182+
label: __( 'Description' ),
183+
name: 'description',
184+
description: __( 'Provide a short description about the unit.' ),
185+
value: $entry->description ?? '',
186+
)
187+
)
188+
)
189+
)
190+
);
128191
return [
129192
'main' => [
130193
'label' => __( 'Name' ),

0 commit comments

Comments
 (0)