Tom H

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

9 posts in this topic

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.

1 person likes this

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

2 people like this

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.

3 people like this

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 benbyf
      Hello,
      Does anyone know whether the is a place detailing the structure your admin theme should take when creating one? e.g. I see UiKit, Reno and Default admin themes all have default.php, init.php, controller.php files, is this a stylisitic choice or a prerequisite for any admin theme module?
      Thanks!
    • By gebeer
      Hello,
      on a fresh 3.0.62 install I have a page reference field 'mypages' with these settings for selectable pages:

      In my site/ready.php I have this hook:
      /** * custom page select */ wire()->addHookAfter('InputfieldPage::getSelectablePages', function($event) { if($event->object->name != 'mypages') return; $pages = new PageArray(); $pages->add($this->pages->get(1)); $ids = $pages->explode('id'); $event->return = $event->pages->getById($ids); }); On a normal page, the hook is working and the mypages field has only 'Home' in the select dropdown .
      But when I put the mypages field inside a repeater, it is not working.
      I have this problem on a project that is in development right now and have spent quite some time to try and find the reason. Then I made a fresh PW install to verify the behavior.
      No matter if repeater dynamic loading is on or off, the page reference field always returns the  set of pages defined by the settings in the page reference field. The hook is ignored.
      Can anyone please verify this and let me know so I can file a bug report. Also if you have an idea how to fix this, I would be happy.
       
    • By regesh
      I have to languages - english and russian.
      I need russian language to be set as default for admin panel. How to do it? Thanks!
    • By Andreas Augustin
      Hello!
      How can I add custom Content to the Admin Theme Footer or Header?
      Is this possible with a hook? I want also to can upgrade easy and don't touch core files...
       
    • By prestoav
      Posting in the hope this helps someone out of a hole!
      Having built 20+ sites on PW in the last couple of years (and loving it...) I came across a really odd situation recently.  The client's IT company and I 've been battling for a couple of weeks and today, finally, we have an answer!
      The site is built and temporarily housed on a shared hosting account we have for development. All tested well here so Access was granted to the client to start adding content. 
      The next day I get a call from the client to say the admin side of the site is logging them out every 30-40 seconds and they have to log back in again each time to continue. I tested again from our office with their login but all worked as expected. Other browsers, PCs etc. were all tried by the client but the problem persisted.  So, I get in my car and drive to the client's site. Sure enough, I see the issue on one of their iMacs. So I open up my MBP, connect to their network, log in as them and the problem is there. So, next, I came off of their network and onto my tethered iPhone on 4G. Bingo! The problem goes away.
      So it's their network that's the issue.
      Their IT company were called and, with us helping them wherever possible, they worked on it for 2 weeks to find the problem. I captured the port numbers in use by PW admin (60992, 60993, 61000, 61001, 61002, 61003 by the way) and the IT company opened those ports on the router but still, the problem remained :-(
      And then the breakthrough...
      They have two VDSL lines into the building that feed their router through a load balancer. It seems that their setup meant that responses to outbound traffic did not necessarily come back in via the same line. Processwire admin does not like this!
      So, the IT company put in a rule to direct all traffic from the IP of the shared hosting through the same route in and out of the building and BOOM! it all works as expected. Phew!
      All's well that end's well but it certainly put us through the wringer tracking it down. Actually, I think it's pretty cool that PW does this. A good extra security measure. Several other CMSs (no names...) worked just fine with this scenario but not PW.
      Anyway, happy client, happy me. Hopefully, this story helps someone else here too.