Forum Replies Created

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • in reply to: Update select options based on another control's value? #56354
    robincornett
    Participant

    Actually, I can swap out the options pretty much the same as I do on the widgets/customizer screens, and it’s working. I just need to fine tune it. There may be a preferred Gutenberg way to do it, but this is working for now.

    in reply to: Update select options based on another control's value? #56347
    robincornett
    Participant

    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!

Viewing 2 posts - 1 through 2 (of 2 total)