Skip to content

Commit 0f9c671

Browse files
committed
fix: set default max_values when enabling allow_multiple toggle
1 parent 499d73e commit 0f9c671

File tree

1 file changed

+8
-13
lines changed

1 file changed

+8
-13
lines changed

src/Filament/Management/Schemas/FieldForm.php

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -357,22 +357,17 @@ public static function schema(bool $withOptionsRelationship = true): array
357357
Toggle::make('settings.allow_multiple')
358358
->inline(false)
359359
->live()
360-
->label(
361-
__(
362-
'custom-fields::custom-fields.field.form.allow_multiple'
363-
)
364-
)
365-
->helperText(
366-
__(
367-
'custom-fields::custom-fields.field.form.allow_multiple_help'
368-
)
369-
)
360+
->label(__('custom-fields::custom-fields.field.form.allow_multiple'))
361+
->helperText(__('custom-fields::custom-fields.field.form.allow_multiple_help'))
370362
->visible(
371-
fn (
372-
Get $get
373-
): bool => FeatureManager::isEnabled(CustomFieldsFeature::FIELD_MULTI_VALUE) &&
363+
fn (Get $get): bool => FeatureManager::isEnabled(CustomFieldsFeature::FIELD_MULTI_VALUE) &&
374364
CustomFieldsType::getFieldType($get('type'))?->supportsMultiValue === true
375365
)
366+
->afterStateUpdated(function (Set $set, bool $state): void {
367+
if ($state) {
368+
$set('settings.max_values', 2);
369+
}
370+
})
376371
->default(false),
377372
TextInput::make('settings.max_values')
378373
->label(

0 commit comments

Comments
 (0)