# \[migxdb\] How to have dynamic listbox options based on other listbox option selection

**URL:** <https://community.modx.com/t/migxdb-how-to-have-dynamic-listbox-options-based-on-other-listbox-option-selection/622>\
**Category:** Support\
**Created:** [April 21, 2019, 6:17pm UTC](https://community.modx.com/t/migxdb-how-to-have-dynamic-listbox-options-based-on-other-listbox-option-selection/622 "2019-04-21T18:17:12Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![jnogueira](https://community.modx.com/letter_avatar_proxy/v4/letter/j/f17d59/32.png) [@jnogueira](https://community.modx.com/u/jnogueira)\
**Post date:** [April 21, 2019, 6:17pm UTC](https://community.modx.com/t/migxdb-how-to-have-dynamic-listbox-options-based-on-other-listbox-option-selection/622/1 "2019-04-21T18:17:12Z")

</div>

### Summary

I am trying to find a way to create nested listboxes where the second listbox will display its options based on what is selected on the first lisbox, but I was not able to find any similar use case.  
Checked on the file `migxformlayouts.config.inc.php`, but didn’t find anything that could be used for this particular situation.

### Step to reproduce

Here is the config json with the particular example I am trying to create;

```
{
  "MIGX_id":1,
  "caption":"Data",
  "print_before_tabs":"0",
  "fields":[
    {
      "MIGX_id":1,
      "field":"author",
      "caption":"Author",
      "description":"Select an author",
      "description_is_code":"0",
      "inputTV":"",
      "inputTVtype":"listbox",
      "validation":"required",
      "configs":{
		"allowBlank":"false",
		"listWidth":"",
		"title":"",
		"typeAhead":"false",
		"typeAheadDelay":"250",
		"listEmptyText":"",
		"stackItems":"false"
	  },
      "restrictive_condition":"",
      "display":"",
      "sourceFrom":"config",
      "sources":"",
      "inputOptionValues":"@SELECT '-' AS `author` UNION ALL (SELECT `name` AS `author`, id FROM `[[+PREFIX]]authors` WHERE `published` = 1)",
      "default":"",
      "useDefaultIfEmpty":"0",
      "pos":1
    },
    {
      "MIGX_id":2,
      "field":"book",
      "caption":"Choose a book",
      "description":"Choose a book from the selected author on the previous box",
      "description_is_code":"0",
      "inputTV":"",
      "inputTVtype":"listbox",
      "validation":"required",
      "configs":"",
      "restrictive_condition":"",
      "display":"",
      "sourceFrom":"config",
      "sources":"",
      "inputOptionValues":"@SELECT '' AS `book` UNION ALL (SELECT `[[+PREFIX]]books`.`name` AS `book`, `[[+PREFIX]]books`.`id` FROM `[[+PREFIX]]books` INNER JOIN `[[+PREFIX]]authors` ON `[[+PREFIX]]authors`.`id` = `[[+PREFIX]]books`.`author_id` WHERE `[[+PREFIX]]books`.`published` = '1' AND `[[+PREFIX]]authors`.`published` = '1' AND `[[+PREFIX]]authors`.`id` = '[[+author]]' ORDER BY `[[+PREFIX]]books`.`id` DESC)",
      "default":"",
      "useDefaultIfEmpty":"0",
      "pos":2
    }
  ],
  "pos":1
}

```

The SQL is working. I tested this filling in an ID by hand simulating the author, and worked properly.

### Observed behavior

When selecting an option on the first lisbox, the second box is not updated.

### Expected behavior

Maybe this already exists, but I was not able to find this information, but maybe there is an option to enable listbox dependencies.

### Environment

MODX 2.7.1 with Migx 2.12.0-pl

* * *

Thank you in advance for your help.

---

<div class="post-metadata">

**Author:** ![bruno17](https://community.modx.com/user_avatar/community.modx.com/bruno17/32/71_2.png) [@bruno17](https://community.modx.com/u/bruno17)\
**Post date:** [April 22, 2019, 6:23pm UTC](https://community.modx.com/t/migxdb-how-to-have-dynamic-listbox-options-based-on-other-listbox-option-selection/622/2 "2019-04-22T18:23:21Z")

</div>

there is [https://modx.com/extras/package/dynamicdropdowntv](https://modx.com/extras/package/dynamicdropdowntv)

---

<div class="post-metadata">

**Author:** ![jnogueira](https://community.modx.com/letter_avatar_proxy/v4/letter/j/f17d59/32.png) [@jnogueira](https://community.modx.com/u/jnogueira)\
**Post date:** [April 22, 2019, 6:36pm UTC](https://community.modx.com/t/migxdb-how-to-have-dynamic-listbox-options-based-on-other-listbox-option-selection/622/3 "2019-04-22T18:36:51Z")

</div>

Hi Bruno,

Thanks for the tip. I was able to find this extra of yours but I couldn’t get it to work. I am a bit loss I must confess. Do you have any example that you can share? Even if it is completely different from the use case I shared here, not a problem.

Many thanks in advance once again

---

<div class="post-metadata">

**Author:** ![jnogueira](https://community.modx.com/letter_avatar_proxy/v4/letter/j/f17d59/32.png) [@jnogueira](https://community.modx.com/u/jnogueira)\
**Post date:** [April 22, 2019, 10:31pm UTC](https://community.modx.com/t/migxdb-how-to-have-dynamic-listbox-options-based-on-other-listbox-option-selection/622/4 "2019-04-22T22:31:09Z")

</div>

Hi Bruno,

I am still fighting with this, but no success.

```
{
  "MIGX_id":1,
  "caption":"Data",
  "print_before_tabs":"0",
  "fields":[
    {
      "MIGX_id":1,
      "field":"author",
      "caption":"Author",
      "description":"Select an author",
      "description_is_code":"0",
      "inputTV":"",
      "inputTVtype":"dynamicdropdown",
      "validation":"required",
      "configs":{
		"allowBlank":"false",
		"listWidth":"",
		"title":"",
		"typeAhead":"false",
		"typeAheadDelay":"250",
		"listEmptyText":"",
		"stackItems":"false",
		"name":"author",
		"group":"AuthorsBooksOptions",
		"packagename":"authors_books",
		"classname":"Authors",
		"idfield":"id",
		"namefield":"name"
	  },
      "restrictive_condition":"",
      "display":"",
      "sourceFrom":"config",
      "sources":"",
      "inputOptionValues":"@SELECT '-' AS `author` UNION ALL (SELECT `name` AS `author`, id FROM `[[+PREFIX]]authors` WHERE `published` = 1)",
      "default":"",
      "useDefaultIfEmpty":"0",
      "pos":1
    },
    {
      "MIGX_id":2,
      "field":"book",
      "caption":"Choose a book",
      "description":"Choose a book from the selected author on the previous box",
      "description_is_code":"0",
      "inputTV":"",
      "inputTVtype":"dynamicdropdown",
      "validation":"required",
      "configs":{
		"allowBlank":"false",
		"listWidth":"",
		"title":"",
		"typeAhead":"false",
		"typeAheadDelay":"250",
		"listEmptyText":"",
		"stackItems":"false",
		"name":"book",
		"group":"AuthorsBooksOptions",
		"packagename":"authors_books",
		"classname":"Books",
		"idfield":"id",
		"namefield":"name",
		"parents":"author",
		"clearOnRefresh":"true",
		"where":{"author_id":"[[+author:default=`999999999999999`]]"}
	  },
      "restrictive_condition":"",
      "display":"",
      "sourceFrom":"config",
      "sources":"",
      "inputOptionValues":"@SELECT '' AS `book` UNION ALL (SELECT `[[+PREFIX]]books`.`name` AS `book`, `[[+PREFIX]]books`.`id` FROM `[[+PREFIX]]books` INNER JOIN `[[+PREFIX]]authors` ON `[[+PREFIX]]authors`.`id` = `[[+PREFIX]]books`.`author_id` WHERE `[[+PREFIX]]books`.`published` = '1' AND `[[+PREFIX]]authors`.`published` = '1' AND `[[+PREFIX]]authors`.`id` = '[[+author]]' ORDER BY `[[+PREFIX]]books`.`id` DESC)",
      "default":"",
      "useDefaultIfEmpty":"0",
      "pos":2
    }
  ],
  "pos":1
}

```

By reading the extra PHPs, I could not find a proper way to use it on Migx, so I am improvising a bit based on the form input names from the extra source code.

If I create the TVs, I am able to use them on the frontend properly, but on Migx it is a real struggle.

Since you are the coder of Migx and dynamicdropdowntv, do you think these two can be integrated?  
I am assuming that I can, as I could use colorpicker successfully as inputTVtype.

Cheers and many thanks once again  
J.Nogueira

---

<div class="post-metadata">

**Author:** ![jnogueira](https://community.modx.com/letter_avatar_proxy/v4/letter/j/f17d59/32.png) [@jnogueira](https://community.modx.com/u/jnogueira)\
**Post date:** [April 24, 2019, 3:07pm UTC](https://community.modx.com/t/migxdb-how-to-have-dynamic-listbox-options-based-on-other-listbox-option-selection/622/5 "2019-04-24T15:07:52Z")

</div>

Hi @bruno17,  
I insisted again, but no go. Can you give me just a hint of what I might be doing wrong?  
Cheers and thanks again for your time.

---

<div class="post-metadata">

**Author:** ![bruno17](https://community.modx.com/user_avatar/community.modx.com/bruno17/32/71_2.png) [@bruno17](https://community.modx.com/u/bruno17)\
**Post date:** [April 25, 2019, 1:03pm UTC](https://community.modx.com/t/migxdb-how-to-have-dynamic-listbox-options-based-on-other-listbox-option-selection/622/6 "2019-04-25T13:03:34Z")

</div>

Usually, I create them as TVs and use inputTV instead inputTVtype. Never tried the dynamicdropdowns with inputTVtype

---

<div class="post-metadata">

**Author:** ![jnogueira](https://community.modx.com/letter_avatar_proxy/v4/letter/j/f17d59/32.png) [@jnogueira](https://community.modx.com/u/jnogueira)\
**Post date:** [April 25, 2019, 1:24pm UTC](https://community.modx.com/t/migxdb-how-to-have-dynamic-listbox-options-based-on-other-listbox-option-selection/622/7 "2019-04-25T13:24:23Z")

</div>

Hi Bruno,

Thanks, no worries. I will try a bit more to see what I can get. If I am able to have a result I will share

Cheers

---

<div class="post-metadata">

**Author:** ![jnogueira](https://community.modx.com/letter_avatar_proxy/v4/letter/j/f17d59/32.png) [@jnogueira](https://community.modx.com/u/jnogueira)\
**Post date:** [April 26, 2019, 3:59pm UTC](https://community.modx.com/t/migxdb-how-to-have-dynamic-listbox-options-based-on-other-listbox-option-selection/622/8 "2019-04-26T15:59:43Z")

</div>

Hi Bruno,

As promised, here is my feedback:  
inputTVtype does not work, unfortunately. All the confiig option names and values were checked on the site\_tmplvars table on the database to be sure that the option names and option values were correct. Even though everything was correct, the only thing I get is a blank field breaking the tabs of Migx, and no conclusive message seen when debug was enabled.

Ended up following your suggestion:  
When I created the TVs and assigned them as InputTV as you suggested, all went just fine and working as expected.

Many thanks for your time once again.

---

<div class="post-metadata">

**Author:** ![system](https://community.modx.com/user_avatar/community.modx.com/system/32/2_2.png) [@system](https://community.modx.com/u/system)\
**Post date:** [April 28, 2019, 3:59pm UTC](https://community.modx.com/t/migxdb-how-to-have-dynamic-listbox-options-based-on-other-listbox-option-selection/622/9 "2019-04-28T15:59:43Z")

</div>

Closed on April 28, 2019, 3:59pm UTC

This topic was automatically closed 2 days after discussion ended and a solution was marked. New replies are no longer allowed. You can open a new topic by clicking the link icon below the original post or solution and selecting “+ New Topic”.
