Note that there are some explanatory texts on larger screens.

plurals
  1. POAutocomplete Change Event firing after button click
    primarykey
    data
    text
    <p>I am using the JQuery UI Autocomplete. I needed it to MustMatch so I set it up like this:</p> <pre><code>$('#MyAutoComplete').autocomplete({ source: result, minLength: 1, change: function (event, ui) { if (!ui.item) { $('#MyAutoComplete').val(''); } } }); </code></pre> <p>Don't worry about the result as the field is populated and is working as expected. When someone types in a value not in the list and clicks off the field, the field gets erased as I wished--except when I click a submit button. A simplified version of my submit handler is:</p> <pre><code>$('#MyButton').get(0).onclick = $('#MyForm').get(0).onsubmit = (function () { $('#MyForm').validate(); var isValid = $('#MyForm').valid(); if (!isValid) { return false; } }); </code></pre> <p>If I click directly from the focused AutoComplete with bad data to the submit button, the submit event happens before the change for the AutoComplete. So the bad data gets submitted. Any other action clears the bad data which causes the submit to fail (because the field is required). </p> <p>Any ideas how to get around this?</p> <p>I have tried adding each of these to the top of the submit event. None made a difference.</p> <pre><code>$('#MyAutoComeplete').data('autocomplete')._trigger('change'); $('#MyAutoComplete').blur(); $('#MyButton').focus(); </code></pre> <hr> <p>Does the combobox feature require a higher version of the script then I am using? If I take this: </p> <pre><code>$('#MyAutoComplete').autocomplete({ source: result, minLength: 1, change: function (event, ui) { if (!ui.item) { $('#MyAutoComplete').val(''); } } }); </code></pre> <p>And turn it into this:</p> <pre><code>$('#MyAutoComplete').combobox({ source: result, minLength: 1, change: function (event, ui) { if (!ui.item) { $('#MyAutoComplete').val(''); } } }); </code></pre> <p>I get this error:</p> <p>JavaScript runtime error: Object doesn't support property or method 'combobox'</p> <p>I am using:</p> <p>jQuery UI 1.8.7</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload