webhoes Posted June 5, 2018 Share Posted June 5, 2018 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 More sharing options...
Ivan Gretsky Posted June 5, 2018 Share Posted June 5, 2018 Not answering you question directly, but to provide alternatives to solve the problem. There is a commercial module by kongondo that does just that. And another open source and free one by justb3a that does something similar. Link to comment Share on other sites More sharing options...
Robin S Posted June 5, 2018 Share Posted June 5, 2018 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 More sharing options...
webhoes Posted June 6, 2018 Author Share Posted June 6, 2018 @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 More sharing options...
webhoes Posted June 6, 2018 Author Share Posted June 6, 2018 Ahh... figured it out. Had some code in ready.php that prevented the initial show. ? 1 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now