Jump to content

Inputfield pageRef from a field (solved)


mel47
 Share

Recommended Posts

Hi

I will try to be clear. I need to create a selection field getting pageRef data from another pageRef inputfield. In real words, admin will choose event_date (will be used site-widely). Those specific dates will further then use in event's template to choose the date of the event. I need (I think) a page because, dates will be changed every year and need to keep track of past events and avoid retyping those dates constantly.  

Dates page
    -  Date1 page contain a field datetime input
    -  Date2 page

Settings page
    - field: Date_selection (PageRef on Dates children)

Event page
    - field: event_date (PageRef on Date_Selection)

Is it possible? How come I could set up a selector to find selectable pages on the subfield event_date to use in my inputfield? 

Thanks

Melanie

 

 

 

Link to comment
Share on other sites

Hi,

One solution: for creating Dates setup a PageTable on your single Dates Page, so that Dates are created by adding items in the table. Actual Date Pages are stored under a Parent according to your setup ("Select a parent from items" on the Details tab of PageTable field).

From then on, you have a parent which can be used for asmSelects. This can be used for your Settings page.

For the Event page, you need to setup "Custom PHP code" for "Selectable pages" under the Input tab of the PageReference inputfield. I've never done this so I'm not the right one to show you a proper example, but this might help you get started:

 

Link to comment
Share on other sites

11 hours ago, szabesz said:

One solution: for creating Dates setup a PageTable on your single Dates Page, so that Dates are created by adding items in the table. Actual Date Pages are stored under a Parent according to your setup ("Select a parent from items" on the Details tab of PageTable field).

From then on, you have a parent which can be used for asmSelects. This can be used for your Settings page.

This part is already done. My problem is the selector. Thanks for the post, I didn't found it. However, I'm not sure what is really implemented in PW. Anyway, I tried many combinations using * (like $pages->find("date_selection=[*], template=config") but I was unable to get a non-null query. If someone else have an idea!

Thanks

  • Like 1
Link to comment
Share on other sites

@mel47, you must use the "Custom PHP code" option, adding a hook to /site/ready.php

$wire->addHookAfter('InputfieldPage::getSelectablePages', function($event) {
    if($event->object->hasField == 'event_date') {
        // Where 1234 is the ID of the settings page
        $event->return = $event->pages->get(1234)->date_selection; // The selectable pages is the value of the "date_selection" field
    }
});

 

  • Like 1
  • Thanks 1
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...