Skip to content

Commit

Permalink
Fix attribute_data validation hydration and dehydration (#1639)
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanmitchell committed Mar 14, 2024
1 parent 23f67a2 commit 172f595
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions packages/admin/src/Support/Forms/AttributeData.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,15 @@ public function getFilamentComponent(Attribute $attribute): Component
] ?? TextField::class;

return $fieldType::getFilamentComponent($attribute)->label(
$attribute->translate('name')
)->formatStateUsing(function ($state) use ($attribute) {
return $state ?: (new $attribute->type);
})->required($attribute->required)
$attribute->translate('name')
)
->formatStateUsing(fn ($state) => ($state ?: (new $attribute->type))->getValue())
->dehydrateStateUsing(function ($state) use ($attribute) {
$field = new $attribute->type;
$field->setValue($state);
return $field;
})
->required($attribute->required)
->default($attribute->default_value);
}

Expand Down

0 comments on commit 172f595

Please sign in to comment.