I have a project in which I am creating a webpage that displays a list of flights that can be filtered by destination, origin, price, and more. To achieve this, I have categorized each flight within a div element using its specific properties as classes. For example, a flight bound for America, departing at 2:40pm, and priced at $300 would be represented as
<div class = "flight America 240PM 300"> *Insert descriptive text here* </div>
However, I realized that this setup allows users to incorrectly filter the flights by entering the wrong information in the input fields. This is because there is no distinction between the different class values. I am looking for a way to restrict user input within each field. I have been experimenting with using a datalist to provide predefined options while still allowing some flexibility for freeform text input so users can easily find their desired filters without excessive scrolling. However, allowing entirely custom filters using the datalist poses a challenge (as observed in https://jsfiddle.net/5mwo6agb/3/). How can I constrain user input to only the choices available in the datalist, while also enabling them to type custom filters in the textbox?
(If my approach seems incorrect, please feel free to advise me, as I am relatively new to JavaScript and HTML).