Skip to content

Fix refreshFormData with Enum#10554

Merged
danharrin merged 3 commits into
filamentphp:3.xfrom
fouteox:3.x
Jan 2, 2024
Merged

Fix refreshFormData with Enum#10554
danharrin merged 3 commits into
filamentphp:3.xfrom
fouteox:3.x

Conversation

@fouteox
Copy link
Copy Markdown
Contributor

@fouteox fouteox commented Dec 29, 2023

Description

If you use refreshFormData on values that are cast as Enums in the Model, the enum will be loaded instead of its value, which will cause a problem when submitting the form.

My PR fixes this problem by iterating through the values to refresh and taking ->value in the case of an Enum.

The solution is certainly not perfect for Filament's framework.

I'll let the experts correct this properly :)

  • Visual changes (if any) are shown using screenshots/recordings of before and after.

Code style

  • composer cs command has been run.

Testing

See my previous comment for this.

  • Changes have been tested.

@danharrin
Copy link
Copy Markdown
Member

When the form is first loaded, the value is an enum instead of a string. Right?

@danharrin danharrin added bug Something isn't working needs more info labels Dec 29, 2023
@danharrin danharrin added this to the v3 milestone Dec 29, 2023
@fouteox
Copy link
Copy Markdown
Contributor Author

fouteox commented Dec 29, 2023

Nope, the first time the component is loaded with the form, it is indeed a string, even if the field is of type Enum.

The issue only occurs when using the refreshFormData function with a casted Enum field.

@danharrin danharrin self-assigned this Dec 31, 2023
@danharrin danharrin merged commit 8b002f8 into filamentphp:3.x Jan 2, 2024
@danharrin
Copy link
Copy Markdown
Member

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working needs more info

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

2 participants