3

I am trying to perform some sort of text field validation before the Autocomplete request results for the inputted text. My code:

<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.

1 Answer 1

5

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.