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 Peter Knight
      I have a PageReference field called related_random where my client selects a particular parent page in the tree.
      On the front end I then need to get a random child page of that page based on some selector values.
      At the moment I'm using a Matrix field and this outputs the page ID (1090) on the front end 
      <?php foreach($page->related_products as $item) { if($item->type == 'related_product') echo " {$item->related_random->title} "; } ?> What I can't get my head around (and what I really want to do to echo some values of that page IDs children 
      Essentially I want to get a maximum 1 random child page of 1090 with a template of product.
      The shoddy selector below is clearly wrong but correct in explaining what I want to do.
      $related_random->child->getRandom("template=product,limit=1") Don't know if that makes any sense? 
       
       
    • By rolisx
      Hi Everyone
      I have a problem here. I have built a site with Processwire on localhost and then transferred to my customer's server. a) it's a windows server (unfortunately) and b) there is a domain-mapping for this site, the domain points to a folder of another domain. Sorry, I can't explain it any better, I don't really understand the different types of servers (why do they have to be different anyway...).
      My problem is, that I see the main website but not the admin page. Do I have to add anything to my .htaccess file?
      I also tried to include web.config file. Not .htaccess nor web.config file have an impact when changing its content. I really have no clue what to do!!
      Links: mcconnellacademy.ch, mcconnellacademy.ch/admin
      Thanks for any pointing in the right direction!
    • 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!