select-pure icon indicating copy to clipboard operation
select-pure copied to clipboard

using inside form creates multiple hidden inputs.

Open antondalgren opened this issue 4 years ago • 3 comments

Hi,

I'm using this inside a form. My html is being rendered as

<select-pure class="form-control" id="tags" multiple="true" name="tags[]">
  <option-pure value="7">asd</option-pure>
  <option-pure value="8">asss</option-pure>
</select-pure>

This generates 5 hidden input fields where only the last one ever gets the select values.

<input type="hidden" name="tags[]">
<input type="hidden" name="tags[]">
<input type="hidden" name="tags[]">
<input type="hidden" name="tags[]">
<input type="hidden" name="tags[]" value="7,8">

antondalgren avatar Jun 16 '21 10:06 antondalgren

If i only render

<select-pure class="form-control" id="tags" multiple="true" name="tags[]">
  <option value="7">asd</option-pure>
  <option value="8">asss</option-pure>
</select-pure>

The resulting html is only one hidden input field, which is what's expected.

antondalgren avatar Jun 16 '21 10:06 antondalgren

I would suggest having them rendered as hidden, one per option-pure element, but make it "disabled" if its not selected.

By doing it this way, it possible to get the selected options as an array in the backend.

expected => ["8", "7"],
current => ["8,7"],

EDIT: Note that the expected values here, are the ones that are received if using a standard

antondalgren avatar Jun 16 '21 10:06 antondalgren

Thanks for the report!

Multiple renderred hidden inputs should not be happening from 2.1.1-alpha.0 version. Not sure about the second issue yet, will have to think about it.

dudyn5ky1 avatar Jul 01 '21 19:07 dudyn5ky1