JQuery UI auto-check

I am trying to do some text field validation before the autocomplete query results for the entered text. My code is:

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

Therefore, when someone enters text in a field, I want to check the valid format before Autocomplete asks for a search for results. I already have a function that returns true all false, I'm just not sure where to call it.

+3
source share
1 answer

- , / . . :

$(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());
    }
  });
});

: http://docs.jquery.com/UI/Autocomplete#event-search

+5

Source: https://habr.com/ru/post/1766233/


All Articles