Two stage selection

Two stage selection

pcjacksonpcjackson Posts: 18Questions: 6Answers: 0
edited October 2019 in Free community support

Is there any way to have two select boxes depend on one another (dependent api perhaps??)?

The situation is: I have a two stage LeftJoin essentially making a structure that looks like this (data obviously not real.)

Mario Series ┐
             ├ Mario ┐
             ┊       ├ Cape
             ┊       └ Fire Flower
             ├ Luigi
             ├ Peach ┐
             ┊       └ Crown
             ├ Toad
             ├ Bowser
             └ Chain Chomp ┐
                           └ Chain
Sonic Series ┐
             ├ Sonic ┐
             ┊       ├ Chaos Emerald
             ┊       └ Frictionless Shoes
             ├ Tails
             ├ Amy
             ├ Big The Cat ┐
             ┊             └ Fishing Pole
             ├ Eggman
             └ Metal Sonic
Zelda Series ┐
             ├ Link
             ├ Zelda
             ├ Weird Old Man ┐
             ┊               └ Wooden Sword
             ├ Ganon
             └ Navi

(Items has a foreign key on characters, which has a foreign key on series.)

What I am attempting to achieve: I am editing the items, and I would like to change who has the item. For instance, I am editing the Fire Flower, and I would like to give it to Navi. In order to do this I would go to the game series selection box and select "Zelda Series," which would then change the character select box (which was initialized with Mario characters because that is the series of current item owner, Mario) to hold Zelda characters instead (with some default selected, for instance Link, because he's first). Is there an example on the website that goes into how to accomplish this or something like this?

This question has accepted answers - jump to:

Answers

  • allanallan Posts: 63,195Questions: 1Answers: 10,412 Site admin
    Answer ✓

    Hi,

    dependent() is indeed the way forward here! Assuming I've understood what you are looking for correctly, have a look at this blog post which details how to do a cascaded select in Editor.

    Regards,
    Allan

  • pcjacksonpcjackson Posts: 18Questions: 6Answers: 0

    While I'm not against performing an AJAX query to retrieve this information in the abstract, I'm curious as to why it's required for this? Shouldn't all of the data needed to repopulate the select boxes in both the blog's use case and my own be locally available?

  • pcjacksonpcjackson Posts: 18Questions: 6Answers: 0

    Circling back and looking at this, I kind of understand why an Ajax query is preferred, the data isn't really in a good format for this kind of search.

  • allanallan Posts: 63,195Questions: 1Answers: 10,412 Site admin
    Answer ✓

    Sorry - I missed your follow up question before. You are correct - it would be possible to include a list of the options that are available for each row in the table and Editor could be told to use that data using the field().update() method (on initEdit).

    The problem with that is that you need to include the list of options for every row - quick very often would be an extra query per row (unless you use a cunning VIEW or CTE). Requesting the options on each edit has a little overhead for the Ajax request, but I think is easier to understand and lower overall overhead.

    Allan

This discussion has been closed.