Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ParentType disable()/enable() fix #705

Merged
merged 1 commit into from
Apr 17, 2023

Conversation

Eloar
Copy link
Contributor

@Eloar Eloar commented Feb 13, 2023

Fields extending ParentType don't act properly when disabled. For example ChoiceType with required rule is not disabled even if asked nicely with disable() method. This is due to fact attr option gets copied to children from parent while rendering but it doesn't contain disabled attribute after disable() method was called.

Fixed disable() and enable() method to act upon ParentType field itself before populating information to children. Added functionality tests to all derivatives (as ParentType is abstract and has no tests written so far).

Don't know why it ads some code from previous PR that was already merged. Those changes were made during Pull Request review.

@Eloar Eloar changed the title Parent disable()/enable() fix ParentType disable()/enable() fix Feb 13, 2023
@Eloar Eloar force-pushed the parent-fix branch 2 times, most recently from 7531347 to 5539a20 Compare February 13, 2023 13:32
@rudiedirkx
Copy link
Collaborator

I dislike ParentType. I don't use ChoiceType, but rdx/laravel-form-builder-extras, because it's so broken in many ways. I'll check out the PR soon, but 23 files changed.... not a good sign.

@Eloar
Copy link
Contributor Author

Eloar commented Feb 13, 2023

I don't understand why my forks master contains 2 commits from label_template feature that were not merged yet pull request was. I use ChoiceType which means dealing with ParentType. I know it has some problems and I finally found a time to fix one that bothered me from time to time.

If you prefer I might rebase those template_label related commits out of my branch. As feature was already merged I would live them there.

@Eloar Eloar force-pushed the parent-fix branch 2 times, most recently from 16e1995 to adf2ca0 Compare February 16, 2023 08:26
@rudiedirkx
Copy link
Collaborator

rudiedirkx commented Feb 28, 2023

Can you remake the diff/PR?, because there's a lot of different stuff in here. That will be confusing in the future.

And can you explain the problem this fixes? Does that problem only happen if you use $field->enable/disable()? (I never do, so I've never seen it.)

- Parent Field when disabled or enabled did only populate information to
its children and forgot about it itself.
- fixed some typing error
- extended tests for disable/enable functionality
- added `attr` population for some ParentType derivatives
- added variant specific config (wrapper_class, label_class,
field_class) for choice type
@Eloar
Copy link
Contributor Author

Eloar commented Apr 12, 2023

I rebased branch to keep just fix commit here and those left commits for label_template option that should be merged with #700 on Dec 17 2022 I will add as separete PR.

@rudiedirkx
Copy link
Collaborator

And can you explain the problem this fixes? Does that problem only happen if you use $field->enable/disable()? (I never do, so I've never seen it.)

@Eloar
Copy link
Contributor Author

Eloar commented Apr 12, 2023

I experience it using ChoiceType field with required rule set on it and form disabled by calling disable() method on it. Some debugging let me found out that not ChoiceType but ParrentType is a problem and certine options are not properly populated from parent to children. This way when whole form is set as disabled ParentType derivative fields stay enabled.

@rudiedirkx
Copy link
Collaborator

Oh man I really don't like (or understand anymore) ParentType. I'm sure this PR fixes your problems, but what about other effects? I only use CollectionType, not ChoiceType, so I can't test this in real code. How confident are your this won't break anything existing? I only see more attribute/option copying to children, not less, and I thought all the copying was the problem. I understand copying disable and enable, but all attributes/options??

@Eloar
Copy link
Contributor Author

Eloar commented Apr 17, 2023

All tests checks out so I would assume it works without breaking those types beyond current state. I use forked version with this fix for some time and have no complaints for neither Choice nor Collection type fields on my forms.

This was done long enough so I'm not sure but it seems some other changes made on already built form are ignored for parent based fields without it. This was a reason why more then 'disabled' attribute is copied.

EDIT: looking through issues I see it is also fix for already reported problem in #536.

@rudiedirkx
Copy link
Collaborator

Alright, let's do it. I can always blame you when someone complains ;)

@rudiedirkx rudiedirkx merged commit f714e49 into kristijanhusak:master Apr 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants