I'm building a custom dependent dropdown form with 2 select inputs.
I've managed to build the form inputs and update them accordingly, but I'm not able to get the dependent select's value in the submit hook.
I think this happens because I changed (via AjaxResponse()/ReplaceCommand
) the $form
in the AJAX callback, and as such, the second input values aren't updated in the $form_state
.
My problem is that I have no simple way of knowing which options will be available either in the first-level select nor in the dependent select, since they come from a 3rd-party API.
Is there any way I can trigger the update of the #options
in the dependent select, without having to render the nested dropdown and changing the $form
so that the nested values are available in the submit
hook?
Or, alternatively, is there anyway I can update the $form_state
so that it knows the newly added #options
of the second select?
#options
populated. After I populate them in the AJAX callback, they show up in the markup, but aren't available in the submit hook to be processed. Can you suggest how to handle this?