jQuery UI Autocomplete Validation
I am trying to perform some sort of text field validation before the Autocomplete request results for the inputted text. My co开发者_运维知识库de:
<script type="text/javascript" src="/scripts/jquery-1.4.2.min.js"></script>
<script type="text/javascript" src="/scripts/jquery-ui-1.8.2.min.js"></script>
<script type="text/javascript">
$(function() {
$("#vnu").autocomplete({
source: "url",
minLength: 1,
delay:200,
focus: function (event, ui) {
$(event.target).val(ui.item.label);
return false;
}
});
});
</script>
<body>
<input type="text" name="vnu" id="vnu" />
</body>
So basically when someone enters text into the field, I want to check for a valid format before lettering Autocomplete request a results lookup. I already have a function written which return true all false, I am just not sure where to call it from.
I have finally figured out a working solution for all those interested, you can use the search event to run any pre request actions/validation. See the search addition in the code below:
$(function() {
$("#vnu").autocomplete({
source: "url",
minLength: 1,
delay:200,
focus: function (event, ui) {
$(event.target).val(ui.item.label);
return false;
},
search: function (event, ui) {
return some_validation($(this).val());
}
});
});
Autocomplete search event reference: http://docs.jquery.com/UI/Autocomplete#event-search
精彩评论