Skip to content

Instantly share code, notes, and snippets.

@esprehn
Created April 10, 2014 00:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save esprehn/10334499 to your computer and use it in GitHub Desktop.
Save esprehn/10334499 to your computer and use it in GitHub Desktop.
(function() {
var requestAutocomplete = HTMLFormElement.prototype.requestAutocomplete;
HTMLFormElement.prototype.requestAutocomplete = function() {
var form = this;
return new Promise(function(resolve, reject) {
requestAutocomplete.call(form);
function cleanup() {
form.removeEventListener(onSuccess);
form.removeEventListener(onError);
}
function onSuccess() {
resolve();
cleanup();
}
function onError(event) {
reject(event.reason);
cleanup();
}
form.addEventListener("autocomplete", onSuccess);
form.addEventListener("autocompleteerror", onError);
});
};
})();
@domenic
Copy link

domenic commented Apr 10, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment