mdbootstrap / TW-Elements

𝙃𝙪𝙜𝙚 collection of Tailwind MIT licensed (free) components, sections and templates 😎
https://tw-elements.com
MIT License
12.77k stars 1.62k forks source link

Select component: Input inherits 'name' attribute #1984

Open dpletiko opened 9 months ago

dpletiko commented 9 months ago

Select component wierd behaviour.

Setting the 'name' attribute to the Select component applies the same 'name' value to the generated Input element.

Submitting the form both select and input values are submitted.

Any reason why the input element inherits the select element 'name' attribute?

Thanks :)

Edit: (added img example) Inspect element example below: 2023-10-05_19:19:46

juujisai commented 9 months ago

Hi! We've added this together with our validation component. We'll recheck if it's necessary.

BTW, how are you submitting the form? With vanilla JS? Using some frameworks or libraries?

vburlak commented 8 months ago

Hey, folks. Stuck into the same issue.

We are customizing multi-select fields in Gravity Forms and processed form data looks like:

For fields with multiple selected options:

- 2 options selected
- option_1_value
- option_2_value

and for fields with single option selected:

- Option 1 Label
- option_1_value

In both cases value of input[data-te-select-input-ref] would be prepended before exact select values in case of using the same name attribute.

UPD: Gravity Forms using Ajax Post request to send all Form fields by name into backend for validation.

AlxndrVgt commented 8 months ago

Same issue when using the searchable select with data-te-select-filter. Both elements, the original <select> and <input data-te-select-input-ref /> get the same name and therefore multiple and different values submitted:

<form>
  <select name="myselect" data-te-select-init data-te-select-filter="true">
    <option value="1">My value</option>
  </select>
</form>

Then reading the values from the form via JavaScript:

const form = document.querySelector('form');

for (const element of form.elements) {
  console.log(element.name + " - " + element.value);
}

This will result in the following:

myselect - My value // from <input>
myselect - 1 // from <select>
juujisai commented 8 months ago

Soon we are going to start working on that. We will most likely remove the name attribute