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 carrdesigns
      In the admin, I am trying to access data from a page that contains an inputfieldand autofill that data into the modal edit window for a new entry.
      For instance, I have a template which contains a PageTable field. When I add a new entry to the PageTable, I want to capture the ID from the originating admin page and add it to a field in the edit modal as a way of linking the new entry back to the originating page. The new PageTable entries are NOT children of the originating page, and cannot be for structural reasons. I have attached an image which I hope will help to clarify the basic result I want to achieve.
      Is there a practical means of accomplishing this? I've been able to achieve something similar with the ConnectPageFields module, but it does not work with PageTable fields. Any input would be much appreciated.

    • By Vinnie
      Hi all, Im trying to fill an options field in all the children of the parent page, after I save it. 
      the options field is configured as multiple select checkboxes. here's the code i have so far:
      $this->addHookAfter('Pages::saved', function($event) { $page = $event->arguments[0]; //set the page if($page->template == 'sport-verenigingen-overzicht') { //get the subcategories from the parent textarea, split on newline $subcats = preg_split('/[\n\r]+/', $page->subcats); //(also tried without imploding and adding the array, also doesnt work) $subcats = implode("|",$subcats); //get the children $children = $page->children(); foreach ($children as $child) { //set the options(sport_categorie is the options field) $child->sport_categorie = $subcats; $child->save('sport_categorie'); } //if i use a normal textfield instead of an optionsfield, //all the children have the correct data e.g: test1|test2|test3 //how to get the values into the options field?? } }); Hope you guys can help! Keep up the good work, I'm loving what you're doing with PW!!
    • By xfroggy
      Hi!
      So I am trying to pull some information from another ProcessWire installation within the admin area (_main.php / page tree from the AdminThemeUikit module).
      $pwpath = "/path/"; $pwurl = "https://url.example"; $pw = new ProcessWire($pwpath , $pwurl); which then gives me this error
       
      I then read that if it is not already in a ProcessWire environment that I would have to include the core, 
      require('/path/to/wire/core/ProcessWire.php'); Which I tried, and makes sense that it already says it is included.
       
      So what now?
       
      Here is my _main.php from the AdminThemeUikit module (work in progress), just for reference
       
    • By cstevensjr

       
      This is the first collaborative project that my wife and myself have worked together on.  The goal was simple --- Create a public online experience that showed off the "Custom Artisan" jewelry that she has made for years.
      https://yellowrosecreations.biz
      The website is built around an e-commerce platform.  Through ongoing work with a new client of mine, I had gotten to know about Ecwid as an e-commerce solution that was tied in closely in with Square (a financial services, merchant services aggregator and mobile payment company).  My work with Ecwid for the past few months afforded me with the opportunity to get this web project up and online in no time.  Let me be clear, while this e-commerce solution works fine, our long term goal is to use Padloper for the online store.  That long term goal is more about controlling where our data resides and being able to freely enhance the total shopping experience.  I already know that a solution based on ProcessWire will give us the ultimate e-commerce flexibility.
      The great thing about the ProcessWire platform is that there are numerous tools that enable you to get things done.  To my delight, I discovered that using the Hanna Code module allowed me to easily integrate Ecwid (which actually means e-commerce widget) code into a ProcessWire website. I will write a separate article about how that works at a later time. 
      The website makes use of the UnSemantic Responsive CSS grid with Zurb Foundation components added/mixed in.  This is an unconventional combination to use, but it works for us.  
      On the ProcessWire side, there were a few critical modules that contributed to gettng this website online:
      TextformatterHannaCode ProcessDatabaseBackups CronjobDatabaseBackup AdminLinksInFrontend ProCache FormBuilder PrevNextTabs WireMailSmtp ImportPagesCSV ProcessEmailToPage MarkupProcesswirePhotoswipe Hanna Code snippets were used throughout to populate the Ecwid Online Shopping Bag, the Ecwid Main Online Store, different Ecwid Product Category Listings, the green Foundation Buttons in the website sidebar and some other webiste features.
      ProcessWire Page Table and Page Reference fields were instrumental in generating the product descriptions that are used on the Ecwid Online Store.  Each jewelry item has it's own page within ProcessWire that can be later used with the Padloper e-commerce solution.

      On the backend side, we were able to create a repository page that keeps track of each product, SKU, pricing and their current disposition status related to the Online Store.

      This has been a fun and fascinating project to work on.  It took us a few weeks to get everything worked out. As I have said before, ProcessWire makes projects of this type possible because you are not limited by the front-end framework you can use.  Even when there are not dedicated modules to incorporate a feature that you like, this platform and it's openness allows you to do things that are impossible to do on other systems.  It just takes a little ingenuity, planning and time on your part to make things work.
       








    • 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 ...