Jump to content

Dependent Selects


DxJR
 Share

Recommended Posts

So, I've tried looking through here and Can't seem to find it. I'm trying to create a situation in the admin where:

 

I have a page reference InputField. When the user chooses one of those pages, from the dropdown, a new Page reference drop down pops up with that pages children in it. I know how to do the "show only if..." thing, but How did I make it dynamically pull in a pages children? Thanks

Link to comment
Share on other sites

Depending on how complex your needs are, the core does offer some support. Use something like this for the selector value for a page field:

parent=page.otherpagefield

That allows for ajax population of one select based on the selected value of the otherpagefield

  • Like 4
Link to comment
Share on other sites

  On 12/8/2017 at 8:10 PM, adrian said:

Depending on how complex your needs are, the core does offer some support. Use something like this for the selector value for a page field:

parent=page.otherpagefield

That allows for ajax population of one select based on the selected value of the otherpagefield

Expand  

Is it possible to apply to fields within repeater? It is working great without using repeater, but it is not when the fields are inside a repeater item even after saving the page.

Link to comment
Share on other sites

I needed the same thing so i used Selectize inputfield single for the master select and then a select multiple on the dependent select, then i initialized the 2nd one using Selectize JS;

the JS is not so hard, but you do need to have a custom select multiple that has a data-parent attribute on each option; those are filtered to match the selected option in the 'parent' select. Eventually this will make it into InputfieldSelectize somehow, but for now it's just done by adding JS, courtesy of AdminCustomFiles..

In the screen capture, you will see the left select, which may or may not have child pages; if it does, then the right one shows the children:

5a2b5e47bb562_dependentselects.thumb.gif.2cbb5f9424cf04d13c70fee32dfdad03.gif

 

  Reveal hidden contents

 

  • Like 9
Link to comment
Share on other sites

Thanks for your solution @Macrura.

I found that the reason why dynamic function is not working. This is because the class of the select field are amended by the repeater so the jquery is not able to select the DOM correctly. What we should do is to fix it by targeting the correct DOM by changing the selector. I can get it to work with already saved repeater page but not the newly added one. I think a listener is needed to attach the on change event to newly added repeater item when we press Add New.

EDIT: The newly added repeater item surprisingly fires the js again. It is working fine now. A small bug is that the old repeater items will fire more than once if there are more than one newly added item.

Below is the amended JS file for InputfieldPage in quick

  Reveal hidden contents

EDIT: The bug is fixed. I have submited a pull request. Hope we could see this feature in the core soon!

  • Like 4
Link to comment
Share on other sites

  • 4 years later...
  On 12/9/2017 at 3:23 AM, Karl_T said:

Is it possible to apply to fields within repeater? It is working great without using repeater, but it is not when the fields are inside a repeater item even after saving the page.

Expand  

As of today, yes!

  On 12/9/2017 at 1:36 PM, Macrura said:

would be awesome if core natively supported dependent selects in repeaters!

Expand  

Your prayers were answered today ?

  • Like 1
Link to comment
Share on other sites

  • 1 year later...
  On 12/8/2017 at 8:10 PM, adrian said:

Depending on how complex your needs are, the core does offer some support. Use something like this for the selector value for a page field:

parent=page.otherpagefield

That allows for ajax population of one select based on the selected value of the otherpagefield

Expand  

Hello @adrian & @Fuzen – I have tried this without success. May I ask you what it needs to set up? I need a second select (field b), that offers options related to the selected value in field a.

Pages structure:
_dir-tpls/
> Template 1 [chunk-tpl]/
>> Option 1 [tpl-option]
>> Option 2 [tpl-option]
>> …
> Template 2 [chunk-tpl]
>> Option …

On a settings page I have these two fields:

field aname: select_tpl, type: select-option-single
config > parent => _dir-tpls/ 
config > template => chunk-tpl

field bname: tpl_options, type: checkbox-multi
config > parent =>  ''
config > template => tpl-option
config > findPagesSelector => 'parent=page.select_tpl'    //include=hidden

It doesn't show any options in the select field b. If I leave the findPagesSelector empty, all option pages [tpl-option] are listet. You say it's a core feature, so I guess it should work without any additional JS? Or did I get you wrong?

I would be happy if you could help me with a hint – thank you!

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

×
×
  • Create New...