JavaScript for WordPress › Forums › Gutenberg Development › Update select options based on another control's value? › Reply To: Update select options based on another control's value?
Sure, I can try to clarify. I’ve extracted my onChange function into a gist. Since I’d already done all of the data retrieval work for the ajax action for the widgets panel once, I wanted to reuse as much of it as I could.
Basically, I have three selectControl elements: post_type
, taxonomy
, and term
. THey are initially populated as Post, Categories, and “any”. On the widgets admin screen, when Post is changed to another post type, the taxonomy and term select controls are updated with the relevant lists of taxonomies/terms (the terms list is also cued to update if the taxonomy is changed).
The ajax call works and properly retrieves the updated lists of options. Where I’m stuck is how to affect the dependent controls. I’ve got a line marked in the code where I’ve determined that I can affect the value of a dependent control, but what I really want to change is the list of options.
On the widgets admin screen, where I started with this code, I know the ID of the dependent select elements, and basically I clear out the options and replace them with the list I’ve just retrieved with the ajax call. That doesn’t seem to be possible here–or, maybe it could be possible, but I haven’t explored that as it seems like it’s probably not the approved way of doing it.
I hope that helps clarify–thank you for any help!