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

Populate the form fields values. #1170

Closed
wants to merge 4 commits into from
Closed

Populate the form fields values. #1170

wants to merge 4 commits into from

Conversation

mjauvin
Copy link
Member

@mjauvin mjauvin commented Jul 23, 2024

Replaces #1126

@LukeTowers
Copy link
Member

LukeTowers commented Jul 23, 2024

@mjauvin is there any chance you could add a unit test that could cover all of the issues we've encountered with this change? (just interacting with the Form widget & some models directly)

@mjauvin
Copy link
Member Author

mjauvin commented Jul 23, 2024

@LukeTowers I'd like to, but I'm not sure I know how to do this.

@LukeTowers
Copy link
Member

@mjauvin are you able to start just by listing out all the problems we've had (starting with the first issue that caused us to want to apply it in multiple locations) describing the original issue, what should have happened, what did happen, and what we did to fix the issue? I should be able to turn those into some unit tests.

@mjauvin
Copy link
Member Author

mjauvin commented Jul 24, 2024

@LukeTowers

Initial PR #927 fixed #950:
When you define a hidden field you want to show in the filterFields() model method, the later is not correctly saved.
This behavior occurs because the model form fields filtering is not applied in the getSaveData() widget method.

PR #1099 Fixed #1036:
Try to access a model attribute via $this (e.g. $this->someAttribute) in the filterFields() method. Before v1.2.4 the model attributes are populated but after v1.2.4 they are all null.

@mjauvin
Copy link
Member Author

mjauvin commented Jul 25, 2024

@LukeTowers just realized this PR probably breaks #950 ...

@mjauvin
Copy link
Member Author

mjauvin commented Jul 25, 2024

I'd really like to know why the form fields AND the model fields are set when filterFields gets called in the Form widget's onRefresh() but not in the FormController's create_onSave() ... there lies the solution to this issue.

@mjauvin mjauvin changed the title Do not apply model filters when saving the model Populate the form fields values. Jul 25, 2024
@mjauvin
Copy link
Member Author

mjauvin commented Jul 25, 2024

@LukeTowers @bennothommo @jaxwilko this is the most promissing fix yet.

If there is no objections from you guys in calling $this->formWidget->setFormValues() from within the FormController's create_onSave / update_onSave methods, this should resolve all issues.

@bennothommo
Copy link
Member

@mjauvin I have no objections if it works, just need to test it in a variety of contexts to make sure it doesn't break something :)

@LukeTowers
Copy link
Member

I'll review this and see if I can build out some tests, I don't want to have to come back to this again.

@mjauvin
Copy link
Member Author

mjauvin commented Aug 7, 2024

@LukeTowers I am still getting a case where having the applyFiltersFromModel() method called in getSaveData() creates an issue when saving a new form.

I surrender, strongly suggest we avoid calling this as done in #1126

@mjauvin
Copy link
Member Author

mjauvin commented Aug 11, 2024

Closing this as it does not resolve the issues.

@mjauvin mjauvin closed this Aug 11, 2024
@bennothommo bennothommo deleted the fix-apply-filters branch August 13, 2024 01:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants