Opinion on validation #148
-
Hey there! Thank god i found your repo. I tried this and that, but your implementation is by far the best autocomplete solution out there. I was wondering about validation. How do you handle that in your own usecases? I'm working on a form where people need to enter their city. More or less, i'm using the same code as in your example with Leaflet.. Now my problem is validation. I want people to be forced to pick one of the suggestions from the list, rather than submitting their own, e.g. wrongly typed city names or even just a part of it. I was thinking of two options:
How would you approach this? Is there a third, even better solution or one that i just oversaw in your docs? Would be cool to hear your thoughts. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Hi, Another approach https://tomik23.github.io/autocomplete/#select-item Good luck |
Beta Was this translation helpful? Give feedback.
Hi,
Probably the simplest approach that you can think of quickly.
A variable that is initially set to false, when someone writes it, it is always false.
When you select it from the list, you change it to true and only then you can submit the form using the button.
When someone wants to enter their own city and send the form, you give info that they can only choose a city from the list.
Only selecting a city from the list changes the value to true.
Another approach https://tomik23.github.io/autocomplete/#select-item
Selecting an element and putting it into input which is set to readonly and giving it the option to do submit.
Good luck