Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Bug #5161 Disallow clear in AssociationField when field is required#6740

Merged
javiereguiluz merged 1 commit into
EasyCorp:4.xfrom
Sobak:fix/non-clearable-required-associations
Jan 21, 2025
Merged

Bug #5161 Disallow clear in AssociationField when field is required#6740
javiereguiluz merged 1 commit into
EasyCorp:4.xfrom
Sobak:fix/non-clearable-required-associations

Conversation

@Sobak
Copy link
Copy Markdown
Contributor

@Sobak Sobak commented Jan 19, 2025

Hi,

This small change closes #5161 and instructs the frontend library to not render the x button for unsetting the association completely.

Admittedly, "extending" the trait methods in PHP is always weird and it's not very common, but it allows for the least amount of code repetition. This approach also doesn't require any JS changes. Please let me know if such approach is acceptable. This is my first contribution so there might be some other rules that I'm not aware of.

Thanks!

@Sobak Sobak force-pushed the fix/non-clearable-required-associations branch from cdce974 to 5e4f5b0 Compare January 19, 2025 03:34
@javiereguiluz javiereguiluz added this to the 4.x milestone Jan 20, 2025
@javiereguiluz
Copy link
Copy Markdown
Collaborator

@Sobak thanks for this contribution. I don't mind the trait extending solution ... but I was wondering, shouldn't we instead add the new code line below these two lines?

$isRequired = $this->buildRequiredOption($field, $entityDto);
$field->setFormTypeOption('required', $isRequired);

@Sobak
Copy link
Copy Markdown
Contributor Author

Sobak commented Jan 21, 2025

Hi @javiereguiluz, thanks for the quick review.

I didn't feel confident enough with the project to suggest such solution, I don't know for sure if it's going to cause some backwards incompatible changes, but if you say it's a sensible behavior for all field types, then I'll update this PR momentarily.

@Sobak Sobak force-pushed the fix/non-clearable-required-associations branch from 5e4f5b0 to 20ff3e4 Compare January 21, 2025 04:13
@Sobak
Copy link
Copy Markdown
Contributor Author

Sobak commented Jan 21, 2025

Done, I force-pushed the commit. I also tested your suggested change with my project manually and it works like expected for AssociationField.

@javiereguiluz
Copy link
Copy Markdown
Collaborator

Nice! I tested this on my apps and everything worked as expected, so I think it's safe to merge it. Thanks for your contribution!

@javiereguiluz javiereguiluz merged commit 89fb2d2 into EasyCorp:4.x Jan 21, 2025
@Sobak Sobak deleted the fix/non-clearable-required-associations branch January 22, 2025 05:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Disallow clear in AssociationField

2 participants