CreativeIT / getmdl-select

Select for material-design-lite
http://creativeit.github.io/getmdl-select/
MIT License
301 stars 87 forks source link

Doesn't work if hidden input is not a sibling. #87

Closed irfabid closed 5 years ago

irfabid commented 6 years ago

I have a requirement where this select element is outside the form but I still need to send value by POST on form submission (Not using any Javascript or framework). So hidden input is inside the form but this select element is outside. It should work by assigning value to hidden element by Id or Name regardless where that element appears.

irfabid commented 6 years ago

I actually modified the source to workaround this. For anyone else wondering:

Change following line:

var hiddenInput = dropdown.querySelector('input[type="hidden"]');

to these two:

 var lab=dropdown.querySelector('label');
 var hiddenInput=document.querySelector('input[name='+lab.htmlFor+']');

Now you just have to set "for" attribute on label to same value as "name" attribute value of target hidden input.

alexbananabob commented 5 years ago

Hi @irfabid,

So hidden input is inside the form but this select element is outside.

getmdl-select library does not provide such the case. All HTML elements for coresponding select should place in div wrap with class getmdl-select. But perhaps your experience will be useful for someone. Thanks