Last active
March 25, 2024 16:15
-
-
Save miwebguy/bf3f2a1bc8e0b8e4c865435b86cc3e89 to your computer and use it in GitHub Desktop.
Only allow valid data from html datalist
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//https://stackoverflow.com/questions/30499199/html5-datalist-to-select-only-predefined-options | |
<script> | |
function peopleCheck(el) | |
{ | |
// nothing is done if no value selected - allow empty | |
if (el.value == "") return; | |
var options = el.list.options; | |
for (var i = 0; i< options.length; i++) { | |
if (el.value == options[i].value) | |
//option matches: work is done | |
return; | |
} | |
//no match was found: reset the value | |
el.value = ""; | |
alert("Does not match to a known person"); | |
el.focus(); | |
} | |
</script> | |
<div class='iwrap'> | |
<label for='ReferredBy'>ReferredBy </label> | |
<input type='text' list='people' name="referrer" onblur='peopleCheck(this)'/> | |
</div> | |
<datalist id='people'> | |
<tal:block tal:repeat = "p principals"> | |
<option value="${p/login}">${p/displayName}</option> | |
</tal:block> | |
</datalist> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment