Skip to content

Commit 978d45d

Browse files
committed
Fix enum dirty state issue in form components
Updated dehydrateStateUsing callbacks to handle all \BackedEnum instances instead of specific enum classes in DocumentTypeCategorySwitcher and NavigationResource. This prevents dirty state issues when working with enums in Filament forms.
1 parent 555d9af commit 978d45d

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

src/Filament/Resources/DocumentTypes/Schemas/Components/DocumentTypeCategorySwitcher.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public static function make()
2121
->options($enumClass)
2222
->default($enumClass::getDefaultValue()->value)
2323
// avoid dirty state issue for model
24-
->dehydrateStateUsing(fn ($state) => $state instanceof DocumentTypeCategory ? $state->value : $state)
24+
->dehydrateStateUsing(fn ($state) => $state instanceof \BackedEnum ? $state->value : $state)
2525
->required()
2626
->live()
2727
->colors(collect($enumClass::cases())->mapWithKeys(fn (DocumentTypeCategory $enumClass): array => [$enumClass->value => $enumClass->getColor()])->all())

src/Filament/Resources/NavigationResource.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,8 @@ protected static function getTypeFormComponent()
265265
$set('is_active', true);
266266
}
267267
})
268+
// avoid dirty state issue for model
269+
->dehydrateStateUsing(fn ($state) => $state instanceof \BackedEnum ? $state->value : $state)
268270
->inline()->grouped();
269271
}
270272

0 commit comments

Comments
 (0)