Jump to content

get children of selected pages in admin


webhoes
 Share

Recommended Posts

Hello,

I have 2 fields in on a template.

field 1 is country and field 2 is state.

states are children of a country.

 

Now if I select one ore more countries I would like to see the children of the selected countries in the field state (select multiple).

I tried something in ready.php but I can't get this to work.

$wire->addHookAfter('InputfieldPage::getSelectablePages', function($event) {
    if($event->object->hasField == 'state') {
        $event->return = $event->pages->find('template=country')->children;
    }
});

 

It this the way to do it, or is another way better?

I don't mind to have to save the page first before I can see the children of the selected countries.

Link to comment
Share on other sites

2 hours ago, webhoes said:

I don't mind to have to save the page first before I can see the children of the selected countries.

You can do it without having to save the page using the (undocumented) core dependent selects feature.

There are some requirements for it to work. More info:

 

Link to comment
Share on other sites

@Robin S, thanks. Your code works excellent but it won't save the selected states. After I save all the options (states) are gone, also the selected ones.

I have selected Select Multiple as input field type.

 

If I want to use something like this: 

return $page->country->children();

Where would I put that?

 

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