Jump to content

Page Reference field not updating with 'Show if...'


Tom H
 Share

Recommended Posts

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

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

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

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

  • Like 3
Link to comment
Share on other sites

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.

  • Like 3
Link to comment
Share on other sites

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

  • 6 years later...
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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...