A user account is required in order to edit this wiki, but we've had to disable public user registrations due to spam.

To request an account, ask an autoconfirmed user on Chat (such as one of these permanent autoconfirmed members).

RequestAutocomplete

From WHATWG Wiki
Jump to navigation Jump to search

Something based on this is now in the HTML standard: http://www.whatwg.org/specs/web-apps/current-work/#dom-form-requestautocomplete

The remainder of this page is for the historical record:

requestAutocomplete proposed spec (as implemented in Chromium)

This document contains a preliminary specification of the requestAutocomplete feature that allows developers to request that the browser fill a form with information based on the autocomplete attributes on the form controls.

Issues

This should really use a promise: http://dom.spec.whatwg.org/#promises (http://crbug.com/343630).

Interfaces Additions

 interface HTMLFormElement : HTMLElement {
   ...
   void requestAutocomplete();
 };
 enum AutoCompleteErrorReason {
   "",
   "cancel",
   "disabled",
   "invalid"
 };
 [Constructor(DOMString type, optional AutocompleteErrorEventInit eventInitDict)]
 interface AutocompleteErrorEvent : Event {
   readonly attribute AutoCompleteErrorReason reason;
 };
 dictionary AutocompleteErrorEventInit : EventInit {
   AutoCompleteErrorReason reason = "";
 };

Algorithms

When the requestAutocomplete() method is invoked, the user agent must run the following steps:

  1. If we are not allowed to show a popup then asynchronously fail with the reason "disabled" and abort these steps.
  2. If the requestAutocompleteIsActive flag is true or the form element's autocomplete attribute evaluates to “off” then asynchronously fail with the reason "disabled" and abort these steps.
  3. Optionally asynchronously fail with the reason "disabled" and abort these steps.
    (For example the user agent may give the user an option to ignore all autocomplete requests.)
  4. Set the requestAutocompleteIsActive flag to true.
  5. Let the pending autofill set be an empty set of autocomplete tuples of the form
    ( autocomplete attribute: string, input: Element )
  6. For each element that has this form element as its form owner add it to the pending autocomplete set with its attribute values if:
    • The autocomplete attribute is specified for its element type.
    • The autocomplete attribute parses to a valid value.
  7. Asynchronously request autocomplete from the user agent for the pending auto fill set for this form element.

When the user agent is said to request autocomplete for a form element it should run the following steps:

  1. Let the autofill set be the set of autocomplete tuples that were passed into this algorithm.
  2. Optionally asynchronously fail with the reason "cancel" and abort these steps. (For example if the user cancels the request.)
  3. For each tuple in the autofill set:
    a. Skip this tuple if the input's attribute value for autocomplete is different than the one stored in the tuple.
    b. Skip this tuple if the form owner of the input is not this form element.
    c. Autofill the input following the autocomplete rules but allowing the input to suffer from a pattern mismatch.
  4. Statically validate the constraints and:
    a. If the result is negative asynchronously fail with the reason "invalid".
    b. If the result is positive fire a simple event named "autocomplete" that bubbles on the form element.
  5. Set the requestAutocompleteIsActive flag to false.

When the user agent is said to asynchronously fail with a reason, it queues an event to fire on the form element currently being operated on of a new AutocompleteErrorEvent with the type "autocompleteerror" and the reason specified.