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

[4.x]: Conditional fields in globals aren't saved #12166

Closed
gglnx opened this issue Oct 20, 2022 · 8 comments · Fixed by #12326
Closed

[4.x]: Conditional fields in globals aren't saved #12166

gglnx opened this issue Oct 20, 2022 · 8 comments · Fixed by #12326
Assignees

Comments

@gglnx
Copy link
Contributor

gglnx commented Oct 20, 2022

What happened?

Description

After saving a global set with conditional fields the conditional fields aren't saved and stay empty. Element::setFieldValuesFromRequest() used in globals/save-content only saves to visible fields and making fields visible beforehand is missing.

Steps to reproduce

  1. Create a global set with two fields (lightswitch and text field for example)
  2. Make the text field depend on the lightswitch field
  3. Try to save content to the text field

Expected behavior

Working and savable conditional fields in global sets.

Actual behavior

Empty conditional fields after saving.

Craft CMS version

4.2.8

PHP version

No response

Operating system and version

No response

Database type and version

No response

Image driver and version

No response

Installed plugins and versions

@i-just i-just self-assigned this Oct 21, 2022
@i-just
Copy link
Contributor

i-just commented Oct 21, 2022

Hi, thanks for getting in touch. I can't seem to replicate this issue in Craft CMS 4.2.8. Could you please confirm if this is happening for you with a standalone lightswitch field and plain text field (where the plain text field is e.g. set to only show if the lightswitch is turned on) or is it happening for a more complex scenario, and if so, could you please provide a bit more info on how to replicate?

@gglnx
Copy link
Contributor Author

gglnx commented Oct 22, 2022

I can't reproduce it either now. That's my field layout:

SCR-20221022-m3v

I removed the conditions, changed the content and added the conditions backs and now it works. Even from clean install now everything works. You can close the ticket I think.

@brandonkelly
Copy link
Member

Weird, let us know if it crops up again.

@andygrn
Copy link

andygrn commented Nov 2, 2022

I believe I'm seeing this issue now too, but on users rather than globals. Craft v4.3.1.

My users have two required custom fields; a dropdown field, and a plain text field conditional on the dropdown value. I don't seem to ever be able to save a user when the plain text field is active, because the plain text field always comes back empty with a 'cannot be blank' error.

This appears to be because Element::setFieldValuesFromRequest() is running Element::fieldLayoutFields($visibleOnly = true) to determine which fields to set, but obviously this is happening before the dropdown field value is populated, so the conditional field is never active and its input is always lost. A bit of a chicken and egg situation, you need to set the field values to determine which field values to set.

Somehow this same setup works fine for entries though - perhaps a side effect of drafts not running full validation? I can zip up a minimal example install if you need it.

@brandonkelly
Copy link
Member

@andygrn Yeah if you can give us specific steps to reproduce that would be helpful.

@andygrn
Copy link

andygrn commented Nov 8, 2022

@brandonkelly Thanks - I've sent a zip to [email protected].

@brandonkelly
Copy link
Member

We got this fixed for the next release via #12326 🎉

@brandonkelly
Copy link
Member

Craft 4.3.2 is out with that fix.

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

Successfully merging a pull request may close this issue.

4 participants