devbridge / jQuery-Autocomplete

Ajax Autocomplete for jQuery allows you to easily create autocomplete/autosuggest boxes for text input fields
https://www.devbridge.com/sourcery/components/jquery-autocomplete/
Other
3.57k stars 1.67k forks source link

onSelect issue #834

Closed blangsmgi closed 2 years ago

blangsmgi commented 2 years ago

I'm having an issue where I want to give the user the option to cancel their selection after making it. In the onSelect function, I'm wrapping the changes I want to make in a window.confirm function call - which works kinda. Only the field from which the selection was made updates, and all others do not. Is there a "preventDefault()" equivalent I can use in the onSelect function or some other way to abort after the user makes a selection?

$('#firstname, #lastname, #email, #phone, #companyname').devbridgeAutocomplete({
  // snipped options and other functions
  onSelect: function (suggestion) {
    if (window.confirm('Are you sure?')) {
      $('#firstname').val(suggestion.firstname);
      $('#lastname').val(suggestion.lastname);
      $('#email').val(suggestion.email);
      $('#phone').val(suggestion.phone);
      $('#companyname').val(suggestion.company);
      $('#clientid').val(suggestion.data);
      $('#address1').val(suggestion.address1);
      $('#address2').val(suggestion.address2);
      $('#city').val(suggestion.city);
      $('#provstate').val(suggestion.provstate);
      $('#pocode').val(suggestion.pocode);
      $('#country').val(suggestion.country);
    }
  },
});
tkirda commented 2 years ago

There is no such equivalent. If not confirmed you can always update input value programmatically.