Jump to content

Selectable Pages -> Custom PHP Code: return value NULL not working


glitterBear
 Share

Recommended Posts

Hi!
I'm quite new to ProcessWire and today I stumbled over an error that occurred when I tried to define the selectable page for a PageSelectField:
 
My situation:
I have 2 PageSelectFields in a template. The first ist for research fields where only max 1 is selectable (Type: Page, Single Page(Page) or boolean false when none selected, Input field type: Select).
The second PageSelectField is for sub-research-fields which are children of the research fields. The selectable pages here should be the children of the research field chosen in the first PageSelectField (research fields), so I  defined the selectable pages here as follows:

$selectables = new PageArray();
if(count($page->project_research_field_selector)>0) {
    $selectables = $page->project_research_field_selector;
}
return $selectables;

Even though I return an empty PageArray in case no research field is selected (first PageSelectField) I only get the following error message:

Fatal error: Call to a member function has() on a non-object in /var/www/processwire/wire/modules/Inputfield/InputfieldPage/InputfieldPage.module on line 253

It seems that the return value is still NULL or at least the call in line 253 (as mentioned above) does not work. My workaround for this was to surround line 253 with  "if($children){ ... }"  but I'm quite sure that this cannot be the solution.

My Question:

Where did I go wrong? Or is this actually a bug? 

Thanks in advance for your help!!!

Link to comment
Share on other sites

Hi, I think your question has already been answered in a different topic here: https://processwire.com/talk/topic/11955-page-field-based-on-parent/

As suggested there, you might even want to use the AJAX way by using the custom selector (instead of custom PHP).
In your case that should be something like:

parent=page.project_research_field_selector

I hope this helps.
 

  • Like 3
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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...