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

Form values no longer available in custom form elements #156

Closed
cvette opened this issue Jul 4, 2022 · 11 comments · Fixed by #160
Closed

Form values no longer available in custom form elements #156

cvette opened this issue Jul 4, 2022 · 11 comments · Fixed by #160
Labels

Comments

@cvette
Copy link

cvette commented Jul 4, 2022

It used to be possible to get the form values in AbstractFormElement::onSubmit(). But $formRuntime->getFormState()->getFormValues() is empty since version 5.3.0.

Steps to reproduce

  1. Create a Form with a custom form element that renders the result of $formRuntime->getFormState()->getFormValues() in onSubmit
  2. Fill out the form and submit

Expected result

array(1)
 'password' (8) => 'aaaa' (4)

Actual result

array(empty)

Affected versions

neos/form 5.3.0

@bwaidelich
Copy link
Member

Do you think that's related to #149 ?

@bwaidelich
Copy link
Member

...or maybe #155 ?

@cvette
Copy link
Author

cvette commented Jul 4, 2022

Reverting #149 makes it work again.

@bwaidelich
Copy link
Member

@cvette could you provide a minimal scenario (or maybe even a breaking test) that demonstrates expected vs actual behavior?

@bwaidelich
Copy link
Member

@cvette If you lack the time you could maybe provide a short code snippet or at least some context: i.e. were you creating a custom form element? what behavior did you expect, etc.? Cheers :)

@cvette
Copy link
Author

cvette commented Jul 10, 2022

It's a custom password confirmation form element, i.e. it checks whether the current value matches the value of another field and adds a validation error, if necessary. Yes, there are better ways to do that.

The issue with this change is, that the values are now assigned after all form element onSubmit() methods are invoked. Previously, they were assigned within the same for-loop, therefore you had at least the values for all elements before the current one. So my implementation relies on the order of form elements, which is a bit fragile per se.

@bwaidelich bwaidelich self-assigned this Jul 11, 2022
@bwaidelich
Copy link
Member

bwaidelich commented Jul 11, 2022

Thanks for the explanation. I can reproduce the issue and added steps to reproduce to the issue description.
I'm not (yet) sure how/if we can solve this while keeping #148 work..
For now you could use the provided PasswordWithConfirmation form element or avoid installing the feature update (composer require "neos/form:<5.3")

@bwaidelich bwaidelich removed their assignment Jul 11, 2022
@dlubitz
Copy link
Contributor

dlubitz commented Sep 2, 2022

Any new ideas here? Have also issues now, with conditional required fields based on values of other fields.

@bwaidelich bwaidelich added the bug label Sep 13, 2022
@bwaidelich
Copy link
Member

@dlubitz I'm still looking for ways around this. Could you share some of your code?

@bwaidelich
Copy link
Member

@cvette @dlubitz I think #160 should solve the issue. Can you confirm?

@dlubitz
Copy link
Contributor

dlubitz commented Sep 13, 2022

@bwaidelich Works very well. Thank you.

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 a pull request may close this issue.

3 participants