Tom H Posted July 17, 2017 Share Posted July 17, 2017 Hello, This is my first post here, I've been using processwire for a while now and having a great time with it! Quick question regarding the Pages field: I am using a multiple-select pages field on the User template, so that a dealer can be associated with each user of certain roles. This works flawlessly without any conditions being set, but if I set 'Show this field only if' to roles=dealer|dealer-admin the field shows and hides as desired, but revert to null when saved. Is there anything I'm missing here? Thanks, Tom Link to comment Share on other sites More sharing options...
heldercervantes Posted July 17, 2017 Share Posted July 17, 2017 Not really giving you a solution, but rather sharing my sympathy. I've had the same problem applying the pages field to the user template with a condition. In my case, I was showing the field if the user had a certain role. As you describe, it shows/hides as expected, but doesn't save. Bummer. Eventually left it open, and added a description telling the admin to "Use this field for yadda yadda on X role users". Link to comment Share on other sites More sharing options...
Robin S Posted July 17, 2017 Share Posted July 17, 2017 The value of each Roles checkbox is the ID of the role, so you must use ID(s) in your "show if" condition. Then the field with the show-if dependency will save as expected. 1 Link to comment Share on other sites More sharing options...
Tom H Posted July 18, 2017 Author Share Posted July 18, 2017 Thank you for the advice, this worked for me! As I mentioned above, the field shows/hides as expected when using the names, so what's the reason the IDs are needed rather than the name for the field to save properly? Link to comment Share on other sites More sharing options...
Robin S Posted July 18, 2017 Share Posted July 18, 2017 1 hour ago, Tom H said: As I mentioned above, the field shows/hides as expected when using the names, so what's the reason the IDs are needed rather than the name for the field to save properly? Not sure why it half-works with role names, but the Roles field is a Page field and the correct way to match a Page field in an inputfield dependency is by ID. https://processwire.com/api/selectors/inputfield-dependencies/#example-page 3 Link to comment Share on other sites More sharing options...
LostKobrakai Posted July 18, 2017 Share Posted July 18, 2017 The difference it that changing the field visibility is handled fully client side in javascript, whereas when it comes to saving the show_if/required_if selectors are validated on the server in php. So naturally having two implementations of the same might result in slightly different behaviour. With users and the roles field being quite restricted entities in processwire it's at least a bit understandable, that things might not work in all constellations. 3 Link to comment Share on other sites More sharing options...
Tom H Posted July 19, 2017 Author Share Posted July 19, 2017 Thank you for clarifying. In some CMSs I've used the conditional fields have been purely visual, I think I'm in the habit of assuming the fields are hidden rather than removed when conditional. Link to comment Share on other sites More sharing options...
LostKobrakai Posted July 20, 2017 Share Posted July 20, 2017 They're just hidden on the frontend, but when saving processwire does make sure that fields, which would be hidden are not saved. Otherwise you'd get errors if hidden fields are required, but not filled. Link to comment Share on other sites More sharing options...
sodesign Posted July 21, 2017 Share Posted July 21, 2017 Makes perfect sense Link to comment Share on other sites More sharing options...
MarkE Posted February 17 Share Posted February 17 On 7/18/2017 at 11:12 AM, Robin S said: Not sure why it half-works with role names, but the Roles field is a Page field and the correct way to match a Page field in an inputfield dependency is by ID. https://processwire.com/api/selectors/inputfield-dependencies/#example-page Resurrecting an old post here! The reference above says "Note: we will soon support specification of page references by /path/to/page/ as well." That was a while back, but still seems not to be the case. I like to use page paths wherever possible, as it is so much easier to see what is happening (although to be safe, setting the page to 'system' may be wise as I doubt it could be made to track moves). Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now