News for hackers. Stuff that matters.
Re:HTML Data List Element by cmg on Wednesday June 23, 2021 @09:23AM (#27604250)
You're also stuck with whatever you put in the option's value attribute - very unlike how a <select> works where the option has text content and a value.

Scenario: You've got customers, who have names and IDs. You want to search by name, but the ID needs to be sent to the server - you're right back to doing some JavaScript hack with a hidden field that gets a data-customerid attribute or whatever off of the selected option from a datalist.

Re:HTML Data List Element by recursive on Wednesday June 23, 2021 @10:33AM (#27605005)
That actually sounds a lot like a <select>. If you need to have the customer ID, you won't be able to do much with just a customer name anyway. If you accept a name, you'd need to accept a separate ID too.
Re:HTML Data List Element by cmg on Wednesday June 23, 2021 @11:21AM (#27605557)
With select you have <option value="123">Customer Name</option> so the user sees Customer Name but submitting the form gets 123. With datalist you only have <option value="Customer Name"/> and the input tied to it gets Customer Name.
Re:HTML Data List Element by recursive on Wednesday June 23, 2021 @01:18PM (#27607117)
Yes. If you want to have the id, then why are you using a text input in the first place? This seems to be exactly the use case for a <select>.
Re:HTML Data List Element by cmg on Wednesday June 23, 2021 @08:18PM (#27612322)
For me, datalist is almost an acceptable compromise for a typical combobox (input + select/dropdown) control. Custom solutions for that require JS and are not accessible or otherwise don't behave as a user would expect a standard input to without lots of extra work.
Re:HTML Data List Element by timw4mail on Wednesday June 23, 2021 @10:11AM (#27604757)
It depends on the browser, but yes, it's a mess.