Tom H

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

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

Share this post


Link to post
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".

Share this post


Link to post
Share on other sites

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.

  • Like 1

Share this post


Link to post
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?

Share this post


Link to post
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 2

Share this post


Link to post
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

Share this post


Link to post
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.

 

 

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
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


  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By Pixrael
      Hi guys!
      What do you think about something like this? Because I use this option regularly in the Windows File Explorer breadcrumb and it's very useful. The drop-down menu can display only published/visible child pages. I've tried to find how to do it as a module, but I'm not a coder with enough skills for that ... or I don't know if I can use hooks to do that ...

    • By AAD Web Team
      Hi,
      I've put in a support request (as a followup on an existing one) for this but it's nearly 10pm Ryan's time, so I thought I'd ask on here just in case someone can help...
      Yesterday we purchased ProDrafts, but I couldn't get the key to validate. Every time I hit submit on the module settings screen the key would be removed from the field I entered it in, and then it would complain about the missing value. I put in a support request and Ryan responded last night. It turned out it was because we're behind a proxy/firewall. He gave me a fix to get around that issue - some code to go into admin.php. I put that code in and saved admin.php, but now I can't even get into our admin anymore!
      (Just to clarify, I took the code back out and saved admin.php but that made no difference. It's definitely not the new code causing the error.)
      The errors relate to a lack of permission on the ProDrafts module (see attached screenshot). We do have a key, but evidently the code Ryan gave me to add the key in via admin.php isn't taking effect before the error is thrown...?
      I tried removing the ProDrafts directory from the modules directory, but that hasn't helped.
      Is there a hook I can put in somewhere to tell it not to load ProDrafts at all, or not check the permissions? Or is there some way to manually uninstall it from the file system?
      Thanks!
      Margaret

    • By SwimToWin
      In my world, Super Users / Editors should only be able to work with Pages and administer users.
      Everything else is the domain of the web master. The purpose is to prevent technically inexperienced editors from destroying core elements of a site, such as fields and templates.
      That leaves me with the question, how to deny Super Users access to Setup, Modules and Roles / Permissions?
      PS: May I also suggest that it shall be possible to set Permission for each of the main menu items - including their sub-menu items.

    • By SwimToWin
      How can I translate the admin buttons that are shown when mousing over a page in the admin interface ("Edit", "View", "New", "Move", "Unpub", "Hide", "Lock", "Trash")?

      The site uses the built-in Language Support module. I am here: /processwire/page/.
      I looked for files to translate in the Languages setup section (/processwire/setup/languages/edit/?id=1234), so far unsuccessfully because I was not able to identify a file to translate.
    • By fbg13
      Lets discuss the new admin theme, there has been very little talk about it, a few questions about its status and some simple designs by a few users.
      Have you played with it? Do you like it? Do you dislike it? Of course I'm not talking about its design, but the way its structured, how it works and the features it offers so far.
      ------------------------------
      I'm working on a purple color scheme for it and it turned out quite well (imo), but one thing I dislike is the use of iframes. I haven't used iframes before so it might be just me, but I'm struggling with them when it comes to javascript.
      When iframes are used all scripts are loaded in every frame, which can lead to unexpected results.
      Javascript is an easy way to add, remove, move etc. elements in the admin, but the iframes complicate things.
      What are your thoughts? Is it just me?
      Here's a screenshot of the purple theme: