Custom form and dropdown list


(Mahearnpad) #1

Hi

 

I've created a custom form with several fields, one of which is a dropdown list. It has no options set in matrix. The options are created using JavaScript, after the DOM has loaded. We get the values using a REST resource and calling an external API.

 

The problem I need to resolve, is that when the form is submitted, the selected value from the dropdown is not sent with the form array. It is also not present on the Thank you page.

 

Does anyone have any idea why this might be?

 

TIA

Michael


(Nic Hubbard) #2

It is because you don't have any matching values in the Custom Form Select question. I have tried what you are doing in the past, and it only worked when I matched the JS with real select options.

 

I think that Matrix does some sort of testing on that question to make sure what was submitted for that field was really an option.


(Bart Banda) #3

One option I've used in the past is to create the field as a text field and then use JS to convert it to a select field or even just hardcode the <select> html field into the form and give it the same name and ID as the text field would have gotten. Matrix won't know what form fields you are using on the front end, all it will know is what data you submit for each field.

 

That should work. 


(Mahearnpad) #4

Hi Bart

The select field is firstly a custom form field (with only one empty option). I then create the other options and values using JS, from the RESTful source.  Is it because the options are not "known" by Matrix after the DOM has loaded (or as Nic has described)?

 

 


(Bart Banda) #5

Hi Bart

The select field is firstly a custom form field (with only one empty option). I then create the other options and values using JS, from the RESTful source.  Is it because the options are not "known" by Matrix after the DOM has loaded (or as Nic has described)?

 

 

 

Most likely, but not 100% sure. If you create it as a text field you can pass it any value you want. 


(Mahearnpad) #6

Yes, that's what I ended up doing. I've had to do the same with the password field (see my other post about this). 

So I've now got 2 hidden fields, 2 more fields than otherwise necessary, in order to handle these values.