Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I recently read an article called <a href="http://furrybrains.com/2009/01/02/capturing-autofill-as-a-change-event/" rel="noreferrer">Capturing AutoFill as a Change Event</a> that just may be what you're looking for. The author created a function called <code>listenForChange()</code> that monitors a field for form autofilling activity (is autofilling even a word?). Since it checks your form really frequently I personally suggest you to only run this a certain number of times. After all a form auto-fill will usually do its work as soon as the page has finished loading.</p> <p>Quoting the original article:</p> <blockquote> <p><em>The plugin makes use of the trigger() and data() functions. In a nutshell, we loop over the input element or set of children input elements, storing their initial value in the data cache provided by the data() function. We then check to see if the stored value matches the value of the input during the current iteration. If so, we do nothing, if not, we manually fire the change event via trigger(). There’s also a bit of logic in there to ignore the element that has focus. We don’t need to worry about this element, since if the value is changed while the user has focus, the change event will be fired as normal when the element is blurred.</em></p> </blockquote> <p>And here's the function itself incase you don't want to go and read the article (which you should):</p> <pre><code>(function($) { $.fn.listenForChange = function(options) { settings = $.extend({ interval: 200 // in microseconds }, options); var jquery_object = this; var current_focus = null; jquery_object.filter(":input").add(":input", jquery_object).focus( function() { current_focus = this; }).blur( function() { current_focus = null; }); setInterval(function() { // allow jquery_object.filter(":input").add(":input", jquery_object).each(function() { // set data cache on element to input value if not yet set if ($(this).data('change_listener') == undefined) { $(this).data('change_listener', $(this).val()); return; } // return if the value matches the cache if ($(this).data('change_listener') == $(this).val()) { return; } // ignore if element is in focus (since change event will fire on blur) if (this == current_focus) { return; } // if we make it here, manually fire the change event and set the new value $(this).trigger('change'); $(this).data('change_listener', $(this).val()); }); }, settings.interval); return this; }; })(jQuery); </code></pre> <p>All credit goes to the owner of FurryBrains.com for writing the article.</p>
    singulars
    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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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