1. 4.10.17 フォームコントロールのインフラ
        1. 4.10.17.1 フォームコントロールの値
        2. 4.10.17.2 可変性
        3. 4.10.17.3 コントロールとフォームの関連付け
      2. 4.10.18 フォームコントロールの共通属性
        1. 4.10.18.1 名前フォームコントロール:name属性
        2. 4.10.18.2 要素の方向を送信する:dirname属性
        3. 4.10.18.3 ユーザー入力長さの制限:maxlength属性
        4. 4.10.18.4 最小入力長の要件を設定する:minlength属性
        5. 4.10.18.5 フォームコントロールの有効化および無効化:disabled属性
        6. 4.10.18.6 フォーム送信属性
        7. 4.10.18.7 オートフィル
          1. 4.10.18.7.1 オートフィルフォームコントロール:autocomplete属性
          2. 4.10.18.7.2 Processing model
      3. 4.10.19 テキストフィールド選択のためのAPI
      4. 4.10.20 制約
        1. 4.10.20.1 定義
        2. 4.10.20.2 Constraint validation
        3. 4.10.20.3 制約検証API
        4. 4.10.20.4 セキュリティ
      5. 4.10.21 フォームの送信
        1. 4.10.21.1 導入
        2. 4.10.21.2 Implicit submission
        3. 4.10.21.3 Form submission algorithm
        4. 4.10.21.4 Constructing the entry list
        5. 4.10.21.5 Selecting a form submission encoding
        6. 4.10.21.6 Converting an entry list to a list of name-value pairs
        7. 4.10.21.7 URL-encoded form data
        8. 4.10.21.8 Multipart form data
        9. 4.10.21.9 Plain text form data
        10. 4.10.21.10 SubmitEventインターフェイス
        11. 4.10.21.11 FormDataEventインターフェイス
      6. 4.10.22 Resetting a form

4.10.17 フォームコントロールのインフラ

4.10.17.1 フォームコントロールの値

多くのフォームコントロールは、checkednessを持つ。(後者は、input要素によってのみ使用される。)これらは、ユーザーがコントロールと対話する方法を記述するために使用される。

コントロールのはそのコントロールの初期状態である。それ自体は、ユーザーの現在の入力と一致しないかもしれない。

たとえば、ユーザーが数字を期待する数値フィールドに単語"three"を入力する場合、ユーザーの入力は文字列"three"であるがコントロールのは変わらないままとなる。また、ユーザーがeメールフィールドに(先頭の空白文字とともに)電子メールアドレス"  awesome@example.com"を入力する場合、ユーザーの入力は文字列"  awesome@example.com"であるが、eメールフィールドに対するブラウザーのUIは(先頭の空白文字なしで)"awesome@example.com"のに直すかもしれない。

inputおよびtextarea要素は、ダーティ値フラグを持つ。これは、とデフォルト値の間の相互作用を追跡するために使用される。falseである場合、valueはデフォルト値を反映する。trueである場合、デフォルト値は無視される。

input, textarea and select elements have a user validity boolean. It is initially set to false.

input要素のmultiple属性に直面する制約バリデーションの動作を定義するために、input要素はまた、別々に定義された複数のを持つことができる。

maxlength属性とminlength属性の動作、およびtextarea要素に固有の他のAPIの動作を定義するために、をもつすべてのフォームコントロールにもAPI値を取得するためのアルゴリズムがある。デフォルトでは、このアルゴリズムは単にコントロールのを返すだけである。

select要素はを持たない。そのoption要素のselectednessが代わりに使用されるものである。

4.10.17.2 可変性

フォームコントロールはmutableとして指定することができる。

これは、ユーザーがフォームコントロールのまたはcheckednessを変更できるかどうか、またはコントロールを自動的に事前入力できるかどうかを(要素が指定されようとなかろうと依存する本仕様での定義及び要件によって)判定する。

4.10.17.3 コントロールとフォームの関連付け

フォームに関連付けられた要素は、要素のフォーム所有者と呼ばれるform要素との関係を持つことができる。フォームに関連付けられた要素form要素に関連付けられない場合、そのフォーム所有者はnullであるといわれる。

フォームに関連付けられた要素は、関連するパーサー挿入フラグを持つ。

Element/input#form

Support in all current engines.

Firefox1+Safari1+Chrome1+
Opera12.1+Edge79+
Edge (Legacy)12+Internet Explorer5.5+
Firefox Android?Safari iOS?Chrome Android?WebView Android?Samsung Internet?Opera Android12.1+

Attributes#attr-form

Support in all current engines.

Firefox1+Safari≤4+Chrome1+
Opera≤12.1+Edge79+
Edge (Legacy)12+Internet Explorer≤6+
Firefox Android?Safari iOS?Chrome Android?WebView Android?Samsung Internet?Opera Android≤12.1+

デフォルトで、フォームに関連付けられた要素が(下記のように)その最も近い祖先form要素に関連付けられるが、記載である場合、これを上書きするためにform属性を指定されてもよい。

この機能は、著者がネストされたform要素に対するサポートの不足を回避することができる。

記載されたフォームに関連付けられた要素が指定されたform属性を持つ場合、その属性の値は、その要素のツリーform要素のIDでなければならない。

The rules in this section are complicated by the fact that although conforming documents or trees will never contain nested form elements, it is quite possible (e.g., using a script that performs DOM manipulation) to generate trees that have such nested elements. They are also complicated by rules in the HTML parser that, for historical reasons, can result in a form-associated element being associated with a form element that is not its ancestor.

When a form-associated element is created, its form owner must be initialized to null (no owner).

When a form-associated element is to be associated with a form, its form owner must be set to that form.

When a listed form-associated element's form attribute is set, changed, or removed, then the user agent must reset the form owner of that element.

When a listed form-associated element has a form attribute and the ID of any of the elements in the tree changes, then the user agent must reset the form owner of that form-associated element.

When a listed form-associated element has a form attribute and an element with an ID is inserted into or removed from the Document, then the user agent must reset the form owner of that form-associated element.

The form owner is also reset by the HTML Standard's insertion steps and removing steps.

To reset the form owner of a form-associated element element:

  1. Unset element's parser inserted flag.

  2. If all of the following are true:

    then return.

  3. Set element's form owner to null.

  4. If element is listed, has a form content attribute, and is connected, then:

    1. If the first element in element's tree, in tree order, to have an ID that is identical to element's form content attribute's value, is a form element, then associate the element with that form element.

  5. Otherwise, if element has an ancestor form element, then associate element with the nearest such ancestor form element.

In the following non-conforming snippet

...
 <form id="a">
  <div id="b"></div>
 </form>
 <script>
  document.getElementById('b').innerHTML =
     '<table><tr><td></form><form id="c"><input id="d"></table>' +
     '<input id="e">';
 </script>
...

the form owner of "d" would be the inner nested form "c", while the form owner of "e" would be the outer form "a".

This happens as follows: First, the "e" node gets associated with "c" in the HTML parser. Then, the innerHTML algorithm moves the nodes from the temporary document to the "b" element. At this point, the nodes see their ancestor chain change, and thus all the "magic" associations done by the parser are reset to normal ancestor associations.

This example is a non-conforming document, though, as it is a violation of the content models to nest form elements, and there is a parse error for the </form> tag.

element.form

HTMLObjectElement/form

Support in all current engines.

Firefox1+Safari3+Chrome1+
Opera12.1+Edge79+
Edge (Legacy)12+Internet Explorer5.5+
Firefox Android?Safari iOS1+Chrome Android?WebView Android?Samsung Internet?Opera Android12.1+

HTMLSelectElement/form

Support in all current engines.

Firefox1+Safari3+Chrome1+
Opera12.1+Edge79+
Edge (Legacy)12+Internet Explorer5.5+
Firefox Android?Safari iOS1+Chrome Android?WebView Android?Samsung Internet?Opera Android12.1+

要素のフォーム所有者を返す。

存在しない場合nullを返す。

Listed form-associated elements except for form-associated custom elements have a form IDL attribute, which, on getting, must return the element's form owner, or null if there isn't one.

ElementInternals/form

Support in all current engines.

Firefox98+Safari16.4+Chrome77+
Opera?Edge79+
Edge (Legacy)?Internet ExplorerNo
Firefox Android?Safari iOS?Chrome Android?WebView Android?Samsung Internet?Opera Android?

Form-associated custom elements don't have form IDL attribute. Instead, their ElementInternals object has a form IDL attribute. On getting, it must throw a "NotSupportedError" DOMException if the target element is not a form-associated custom element. Otherwise, it must return the element's form owner, or null if there isn't one.

4.10.18 フォームコントロールの共通属性

4.10.18.1 名前フォームコントロール:name属性

Element/input#name

Support in all current engines.

Firefox1+Safari1+Chrome1+
Opera12.1+Edge79+
Edge (Legacy)12+Internet Explorer5.5+
Firefox Android?Safari iOS?Chrome Android?WebView Android?Samsung Internet?Opera Android12.1+

nameコンテンツ属性は、フォームの送信form要素のelementsオブジェクトで使用されるような、フォームコントロールの名前を与える。属性が指定される場合、その値は空の文字列またはでisindexあってはならない。

多くのユーザーエージェントは歴史的に、名前isindexをもつフォームの最初のテキストコントロールを特別にサポートしており、この仕様は以前に関連するユーザーエージェント要件が定義されていた。しかし、一部のユーザーエージェントは、その後、その特別なサポートを削除し、関連する要件はこの仕様から削除された。よって、レガシーユーザーエージェントで問題のある再解釈を避けるために、isindexという名前はもはや許可されない。

isindex以外で、nameに対して任意の空でない値が許可される。ASCII大文字・小文字不区別で一致する名前_charset_は特別である:value属性のないHiddenコントロールの名前として使用される場合、送信の間value属性は送信文字エンコーディングから成る送信の間の値を自動的に与えられる。

name IDL属性は、nameコンテンツ属性を反映しなければならない。

DOMの上書きは、よくあるセキュリティの問題の原因である。nameコンテンツ属性で組み込みフォームプロパティの名前を使用することを避ける。

この例において、input要素は組み込みmethod のプロパティを上書きする:

let form = document.createElement("form");
let input = document.createElement("input");
form.appendChild(input);

form.method;           // => "get"
input.name = "method"; // DOM clobbering occurs here
form.method === input; // => true

入力名は組み込みのフォームプロパティよりも優先されるため、JavaScript参照form.methodは組み込みのmethodプロパティの代わりに"method"という名前のinput要素を指す。

4.10.18.2 要素の方向を送信する:dirname属性

Element/input#dirname

Support in all current engines.

Firefox116+Safari6+Chrome17+
Opera12.1+Edge79+
Edge (Legacy)?Internet ExplorerNo
Firefox Android?Safari iOS?Chrome Android?WebView Android?Samsung Internet?Opera Android12.1+

dirname属性は要素の方向の送信を有効にし、フォーム送信の間にこの値を含むコントロール名を与える。そのような属性が指定される場合、その値は空文字列であってはならない。

この例において、フォームはテキストコントロールと送信ボタンを含む:

<form action="addcomment.cgi" method=post>
 <p><label>Comment: <input type=text name="comment" dirname="comment.dir" required></label></p>
 <p><button name="mode" type=submit value="add">Post Comment</button></p>
</form>

ユーザーがフォームを送信するとき、ユーザーエージェントは、"comment"、"comment.dir"、"mode"と呼ばれる3つのフィールドを含む。よって、ユーザーが"Hello"を打ち込んだ場合、送信ボディはこのようになるかもしれない:

comment=Hello&comment.dir=ltr&mode=add

ユーザーが手動で右から左へ記述方向に切り替え、"مرحبًا"を入力した場合、送信本体はこのようになるかもしれない:

comment=%D9%85%D8%B1%D8%AD%D8%A8%D8%A7&comment.dir=rtl&mode=add
4.10.18.3 ユーザー入力長さの制限:maxlength属性

ダーティ値フラグによって制御される、フォームコントロールmaxlength属性は、ユーザーが入力できる文字数の制限を宣言する。文字数は、長さを使って測定され、そして、textarea要素の場合は、すべての改行が1文字に正規化される(CRLFの対とは対照的に)。

要素がフォームコントロールmaxlength属性を指定される場合、属性値は妥当な非負の整数でなければならない。属性が指定され、数をもたらすその値に非負整数を解析するための規則を適用する場合、その数は要素の最大許容値の長さである。属性を省略する、またはその値を解析しエラーとなる場合、最大許容値の長さは存在しない。

Constraint validation: If an element has a maximum allowed value length, its dirty value flag is true, its value was last changed by a user edit (as opposed to a change made by a script), and the length of the element's API value is greater than the element's maximum allowed value length, then the element is suffering from being too long.

User agents may prevent the user from causing the element's API value to be set to a value whose length is greater than the element's maximum allowed value length.

In the case of textarea elements, the API value and value differ. In particular, newline normalization is applied before the maximum allowed value length is checked (whereas the textarea wrapping transformation is not applied).

4.10.18.4 最小入力長の要件を設定する:minlength属性

ダーティ値フラグによって制御されるフォームコントロールminlength属性は、ユーザーが入力できる文字数の下限を宣言する。"文字数"は、長さを使って測定され、そして、textarea要素の場合は、すべての改行が1文字に正規化される(CRLFの対とは対照的に)。

minlength属性はrequired属性を暗示しない。フォームコントロールがminlength属性を一切持たない場合、値は依然として省略できる。minlength属性は、ユーザーがすべて値を入力した後にのみ蹴る。空文字列が許可されない場合、required属性も設定する必要がある。

要素がフォームコントロールminlength属性を指定される場合、属性値は妥当な非負の整数でなければならない。属性が指定され、数をもたらすその値に非負整数を解析するための規則を適用する場合、その数は要素の最小許容値の長さである。属性を省略する、またはその値を解析しエラーとなる場合、最小許容値の長さは存在しない。

要素が最大許容値の長さ最小許容値の長さの両方を持つ場合、最小許容値の長さ最大許容値の長さ以下でなければならない。

Constraint validation: If an element has a minimum allowed value length, its dirty value flag is true, its value was last changed by a user edit (as opposed to a change made by a script), its value is not the empty string, and the length of the element's API value is less than the element's minimum allowed value length, then the element is suffering from being too short.

この例において、4つのテキストコントロールが存在する。1つめは必須であり、少なくとも5文字である必要がある。他の3つは任意だが、ユーザーは1つを記入する場合、ユーザーは少なくとも10文字を入力する必要がある。

<form action="/events/menu.cgi" method="post">
 <p><label>Name of Event: <input required minlength=5 maxlength=50 name=event></label></p>
 <p><label>Describe what you would like for breakfast, if anything:
    <textarea name="breakfast" minlength="10"></textarea></label></p>
 <p><label>Describe what you would like for lunch, if anything:
    <textarea name="lunch" minlength="10"></textarea></label></p>
 <p><label>Describe what you would like for dinner, if anything:
    <textarea name="dinner" minlength="10"></textarea></label></p>
 <p><input type=submit value="Submit Request"></p>
</form>
4.10.18.5 フォームコントロールの有効化および無効化:disabled属性

Attributes/disabled

Support in all current engines.

Firefox1+Safari4+Chrome1+
Opera?Edge79+
Edge (Legacy)12+Internet ExplorerYes
Firefox Android?Safari iOS?Chrome Android?WebView Android?Samsung Internet?Opera Android?

Attributes/disabled

Support in all current engines.

Firefox4+Safari6+Chrome20+
Opera12+Edge79+
Edge (Legacy)12+Internet ExplorerYes
Firefox Android?Safari iOS?Chrome Android?WebView Android?Samsung Internet?Opera Android12+

Attributes/disabled

Support in all current engines.

Firefox1+Safari1+Chrome1+
Opera12.1+Edge79+
Edge (Legacy)12+Internet Explorer5.5+
Firefox Android?Safari iOS?Chrome Android?WebView Android?Samsung Internet?Opera Android12.1+

Attributes/disabled

Support in all current engines.

Firefox1+Safari3+Chrome1+
Opera?Edge79+
Edge (Legacy)12+Internet ExplorerYes
Firefox Android?Safari iOS?Chrome Android?WebView Android?Samsung Internet?Opera Android?

Attributes/disabled

Support in all current engines.

Firefox1+Safari4+Chrome1+
Opera12.1+Edge79+
Edge (Legacy)12+Internet Explorer6+
Firefox Android?Safari iOS?Chrome Android?WebView Android?Samsung Internet?Opera Android12.1+

disabledコンテンツ属性は、真偽属性である。

option要素に対するdisabled属性およびoptgroup要素に対するdisabled属性は、別々に定義されている。

A form control is disabled if any of the following are true:

無効であるフォームコントロールは、要素に送出されていることからユーザーインタラクションタスクソース上のキューに入れられる任意のclickイベントを防がなければならない。

Constraint validation: If an element is disabled, it is barred from constraint validation.

HTMLButtonElement/disabled

Support in all current engines.

Firefox1+Safari3+Chrome1+
Opera12.1+Edge79+
Edge (Legacy)12+Internet Explorer5.5+
Firefox Android?Safari iOS1+Chrome Android?WebView Android?Samsung Internet?Opera Android12.1+

HTMLSelectElement/disabled

Support in all current engines.

Firefox1+Safari3+Chrome1+
Opera9+Edge79+
Edge (Legacy)12+Internet Explorer5.5+
Firefox Android?Safari iOS1+Chrome Android?WebView Android?Samsung Internet?Opera Android10.1+

disabled IDL属性は、disabledコンテンツ属性を反映しなければならない。

4.10.18.6 フォーム送信属性

Element/form#Attributes_for_form_submission

Support in all current engines.

Firefox4+Safari10.1+Chrome10+
Opera?Edge79+
Edge (Legacy)12+Internet Explorer10+
Firefox Android?Safari iOS?Chrome Android?WebView Android37+Samsung Internet?Opera Android?

フォーム送信のための属性は、form要素上と送信ボタン上(フォーム送信ボタンを表す要素、たとえば、type属性のinput要素がSubmit Button状態にある)の両方を指定できる。

form要素で指定されてもよいフォーム送信のための属性は、actionenctypemethodnovalidatetargetである。

送信ボタンで指定されてもよい対応するフォーム送信のための属性は、formactionformenctypeformmethodformnovalidateformtargetである。省略した場合、これらはform要素の対応する属性で指定された値をデフォルトとする。


Element/input#formaction

Support in all current engines.

Firefox4+Safari5+Chrome9+
Opera12.1+Edge79+
Edge (Legacy)12+Internet Explorer10+
Firefox Android?Safari iOS?Chrome Android?WebView Android3+Samsung Internet?Opera Android12.1+

指定される場合、actionおよびformactionコンテンツ属性は、潜在的にスペースで囲まれた妥当な空でないURLである値を持たなければならない。

要素が送信ボタンでありかつそのような属性を持つ場合、要素のactionはその要素のformaction属性値である。すなわちactionがそのような属性を持つ場合、そのフォーム所有者action属性値であり、そうでなければ空文字列である。


Element/input#formmethod

Support in all current engines.

Firefox4+Safari5+Chrome9+
Opera12.1+Edge79+
Edge (Legacy)12+Internet Explorer10+
Firefox Android?Safari iOS?Chrome Android?WebView Android3+Samsung Internet?Opera Android12.1+

methodおよびformmethodコンテンツ属性以下のキーワードおよび状態をもつ列挙属性である:

キーワード状態概要
getGETIndicates the form will use the HTTP GET method.
postPOSTIndicates the form will use the HTTP POST method.
dialogDialogIndicates the form is intended to close the dialog box in which the form finds itself, if any, and otherwise not submit.

The method attribute's missing value default and invalid value default are both the GET state.

The formmethod attribute has no missing value default, and its invalid value default is the GET state.

要素のメソッドはこれらの状態のいずれかである。要素が送信ボタンでありかつformmethod属性を持つ場合、要素のメソッドはその属性の状態である。そうでなければ、フォーム所有者method属性状態である。

ここで検索クエリーがURLに提出されるように、method属性は明示的にデフォルト値"get"を指定するために使用される:

<form method="get" action="/search.cgi">
 <p><label>Search terms: <input type=search name=q></label></p>
 <p><input type=submit></p>
</form>

一方で、ユーザーのメッセージがHTTPリクエストのボディに送信されるように、ここでmethod属性は、値"post"を指定するために使用される:

<form method="post" action="/post-message.cgi">
 <p><label>Message: <input type=text name=m></label></p>
 <p><input type=submit value="Submit message"></p>
</form>

この例において、formdialogとともに使用される。フォームの送信時に、method属性の"dialog"キーワードは、自動的に閉じるダイアログを持つために使用される。

<dialog id="ship">
 <form method=dialog>
  <p>A ship has arrived in the harbour.</p>
  <button type=submit value="board">Board the ship</button>
  <button type=submit value="call">Call to the captain</button>
 </form>
</dialog>
<script>
 var ship = document.getElementById('ship');
 ship.showModal();
 ship.onclose = function (event) {
   if (ship.returnValue == 'board') {
     // ...
   } else {
     // ...
   }
 };
</script>

Element/input#formenctype

Support in all current engines.

Firefox4+Safari5+Chrome9+
Opera12.1+Edge79+
Edge (Legacy)12+Internet Explorer10+
Firefox Android?Safari iOS?Chrome Android?WebView Android3+Samsung Internet?Opera Android12.1+

enctypeおよびformenctypeコンテンツ属性は、次のキーワードおよび状態をもつ列挙属性である:

The attribute's missing value default and invalid value default are both the application/x-www-form-urlencoded state.

The formenctype attribute has no missing value default, and its invalid value default is the application/x-www-form-urlencoded state.

要素のenctypeはこれらの状態のいずれかである。要素が送信ボタンでありかつformenctype属性を持つ場合、要素のenctypeはその属性の状態である。そうでなければ、フォーム所有者enctype属性状態である。


Element/input#formtarget

Support in all current engines.

Firefox4+Safari5+Chrome9+
Opera12.1+Edge79+
Edge (Legacy)12+Internet Explorer10+
Firefox Android?Safari iOS?Chrome Android?WebView Android3+Samsung Internet?Opera Android12.1+

指定される場合、targetおよびformtargetコンテンツ属性は、妥当なナビゲート可能名またはキーワードである値を持たなければならない。


Element/input#formnovalidate

Support in all current engines.

Firefox4+Safari5+Chrome4+
Opera12.1+Edge79+
Edge (Legacy)12+Internet Explorer10+
Firefox Android?Safari iOS4+Chrome Android?WebView Android37+Samsung Internet?Opera Android12.1+

novalidateおよびformnovalidate属性は真偽属性である。存在する場合、フォームが送信時に検証されないことを示す。

要素が送信ボタンでありかつ要素のformnovalidate属性が存在する場合、または要素のフォーム所有者novalidate属性が存在する場合、要素のno-validate stateはtrueである。そうでなければfalseである。

属性がフォームでデータを完全に入力していないにもかかわらず、ユーザーが自分の進捗状況を保存できるように、この属性は検証の制約を持つフォーム上のボタン"保存"を含めると便利である。次の例は、2つの必須フィールドを持つ単純なフォームを示す。3つのボタンがある。1つは、両方のフィールドに値が入力されている必要があるフォームを提出するためのもの、1つはユーザーが戻ってきて、後で埋めることができるようにフォームを保存するためのもの、1つは完全にフォームをキャンセルするためのものである。

<form action="editor.cgi" method="post">
 <p><label>Name: <input required name=fn></label></p>
 <p><label>Essay: <textarea required name=essay></textarea></label></p>
 <p><input type=submit name=submit value="Submit essay"></p>
 <p><input type=submit formnovalidate name=save value="Save essay"></p>
 <p><input type=submit formnovalidate name=cancel value="Cancel"></p>
</form>

HTMLFormElement/action

Support in all current engines.

Firefox1+Safari3+Chrome1+
Opera12.1+Edge79+
Edge (Legacy)12+Internet Explorer5.5+
Firefox Android?Safari iOS1+Chrome Android?WebView Android?Samsung Internet?Opera Android12.1+

HTMLFormElement/target

Support in all current engines.

Firefox1+Safari3+Chrome1+
Opera12.1+Edge79+
Edge (Legacy)12+Internet Explorer5.5+
Firefox Android?Safari iOS1+Chrome Android?WebView Android?Samsung Internet?Opera Android12.1+

HTMLFormElement/method

Support in all current engines.

Firefox1+Safari3+Chrome1+
Opera12.1+Edge79+
Edge (Legacy)12+Internet Explorer5.5+
Firefox Android?Safari iOS1+Chrome Android?WebView Android?Samsung Internet?Opera Android12.1+

HTMLFormElement/enctype

Support in all current engines.

Firefox1+Safari3+Chrome1+
Opera12.1+Edge79+
Edge (Legacy)12+Internet Explorer6+
Firefox Android?Safari iOS1+Chrome Android?WebView Android?Samsung Internet?Opera Android12.1+

HTMLFormElement/encoding

Support in all current engines.

Firefox1+Safari3+Chrome1+
Opera12.1+Edge79+
Edge (Legacy)12+Internet Explorer5.5+
Firefox Android?Safari iOS1+Chrome Android?WebView Android?Samsung Internet?Opera Android12.1+

The action IDL attribute must reflect the content attribute of the same name, except that on getting, when the content attribute is missing or its value is the empty string, the element's node document's URL must be returned instead. The target IDL attribute must reflect the content attribute of the same name. The method and enctype IDL attributes must reflect the respective content attributes of the same name, limited to only known values. The encoding IDL attribute must reflect the enctype content attribute, limited to only known values. The noValidate IDL attribute must reflect the novalidate content attribute. The formAction IDL attribute must reflect the formaction content attribute, except that on getting, when the content attribute is missing or its value is the empty string, the element's node document's URL must be returned instead. The formEnctype IDL attribute must reflect the formenctype content attribute, limited to only known values. The formMethod IDL attribute must reflect the formmethod content attribute, limited to only known values. The formNoValidate IDL attribute must reflect the formnovalidate content attribute. The formTarget IDL attribute must reflect the formtarget content attribute.

4.10.18.7 オートフィル
4.10.18.7.1 オートフィルフォームコントロール:autocomplete属性

Attributes/autocomplete

Support in all current engines.

Firefox4+Safari6+Chrome14+
Opera12.1+Edge79+
Edge (Legacy)NoInternet ExplorerNo
Firefox Android?Safari iOS?Chrome Android?WebView Android?Samsung Internet?Opera Android12.1+

ユーザーエージェントは、たとえば以前のユーザー入力に基づくユーザーのアドレスを事前に入力するなど、ユーザーにフォームの記入を助けるための機能を持つこともある。autocompleteコンテンツ属性は、ユーザーエージェントへのヒントの手段に、または実際にそのような機能を提供するかどうかに使用できる。

この属性が使用される2つの状態が存在する。オートフィル予想マントの着用時、autocomplete属性は、入力がユーザーから予想されるものについて説明する。オートフィルアンカーマントの着用時、autocomplete属性は、指定された値の意味を説明する。

type属性がHidden状態にあるinput要素では、autocomplete属性は、オートフィルアンカーマントを着用する。他のすべての場合で、オートフィル予想マントを着用する。

オートフィル予想マントを着用時、autocomplete属性が指定される場合、文字列"off"と一致するASCII大文字・小文字不区別である単一のトークン、または文字列"on"と一致するASCII大文字・小文字不区別である単一のトークン、またはオートフィル詳細トークンのいずれかから成る順序付きのスペースで区切りトークンの集合である値を持たなければならない。

オートフィルアンカーマントを着用時、autocomplete属性が指定される場合、ちょうどオートフィル詳細トークンから成る順序付きのスペースで区切りトークンの集合の値を持たなければならない(すなわち、"on"と"off"キーワードが許可されない)。

オートフィルの詳細トークンは下記の順序で、次のとおり:

  1. 任意で、フィールドが名前グループに属することを意味する、最初の8文字が文字列"section-"とASCII大文字・小文字不区別で一致するトークン。

    たとえば、フォームで2つの配送先住所がある場合、次のようにマークアップできる:

    <fieldset>
     <legend>Ship the blue gift to...</legend>
     <p> <label> Address:     <textarea name=ba autocomplete="section-blue shipping street-address"></textarea> </label>
     <p> <label> City:        <input name=bc autocomplete="section-blue shipping address-level2"> </label>
     <p> <label> Postal Code: <input name=bp autocomplete="section-blue shipping postal-code"> </label>
    </fieldset>
    <fieldset>
     <legend>Ship the red gift to...</legend>
     <p> <label> Address:     <textarea name=ra autocomplete="section-red shipping street-address"></textarea> </label>
     <p> <label> City:        <input name=rc autocomplete="section-red shipping address-level2"> </label>
     <p> <label> Postal Code: <input name=rp autocomplete="section-red shipping postal-code"> </label>
    </fieldset>
  2. 任意で、以下の文字列のいずれかとASCII大文字・小文字不区別で一致するトークン:

  3. 次の2つのオプションについていずれか:

  4. オプションで、文字列"webauthn"とASCII大文字小文字不区別で一致するトークン。これは、ユーザーエージェントは、ユーザーがフォームコントロールを操作するときに、conditionalメディエーションを介して利用可能な公開鍵クレデンシャルを表示すべきであることを意味する。 webauthnは、input要素とtextarea要素に対してのみ有効である。

先に述べたように、属性およびそのキーワードの意味は属性が着用するマントに依存する。

オートフィル予想マント着用時は

"off"キーワードは、コントロールの入力データが特にセンシティブ(たとえば、核兵器のアクティベーションコード)である、またはキーワードが再利用されることのない値(たとえば、銀行のログインのためのワンタイムキー)であり、したがってユーザーは、値を事前入力するためにユーザーエージェントを当てにできる代わりに、明示的にデータを毎回入力する必要がある、または文書は独自のオートコンプリートのメカニズムを提供し、ユーザーエージェントに自動補完値を提供したくないことのいずれかを示す。

"on"キーワードは、ユーザーエージェントが、オートコンプリート値をユーザーに提供することを許可するが、ユーザーが入力すると予想されるだろうデータの種類についてのさらなる情報を提供しないことを示す。ユーザーエージェントは、自動補完が提案する値を決定するためにヒューリスティックを使用する必要があるだろう。

上記のオートフィルフィールドは、ユーザーエージェントがオートコンプリート値をユーザーに提供することができ、かつどの値の種類が期待されるかを指定することを示す。そのような各キーワードの意味は、以下の表に記載される。

autocomplete属性が省略される場合、要素のフォーム所有者autocomplete属性に関する状態に対応するデフォルト値が("on"または"off"のいずれか)の代わりに使用される。フォーム所有者が存在しない場合、値"on"が使用される。

オートフィルアンカーマントを着用時

上記のオートフィルフィールドは、指定される値の特定の種類の値が、この要素のために提供される値であることを示す。そのような各キーワードの意味は、以下の表に記載される。

この例において、ページは明示的にトランザクションの通貨と金額を指定している。フォームは、クレジットカードや他の請求の詳細を要求する。ユーザーエージェントは、十分なバランスを有し、関連する通貨をサポートしていることを知るクレジットカードを提示するためにこの情報を使用することができる。

<form method=post action="step2.cgi">
 <input type=hidden autocomplete=transaction-currency value="CHF">
 <input type=hidden autocomplete=transaction-amount value="15.00">
 <p><label>Credit card number: <input type=text inputmode=numeric autocomplete=cc-number></label>
 <p><label>Expiry Date: <input type=month autocomplete=cc-exp></label>
 <p><input type=submit value="Continue...">
</form>

以下の表に示すように、オートフィルフィールドキーワードは相互に関連する。このテーブルの行に記載された各フィールド名は、"意味"で分類される列で、その行のセルに与えられた意味に対応する。一部のフィールドは、他のフィールドのサブパーツに対応する。たとえば、クレジットカードの有効期限は、有効期限の年と月の両方を1つのフィールドに与える("cc-exp")、または月を与える("cc-exp-month")および年を与える("cc-exp-year")の2つのフィールドとして表すことができる。このような場合、より広いフィールドの名前は、より狭いフィールドを定義する複数行を取り扱う。

一般に、狭いフィールドは西洋バイアスを公開する傾向があるので、著者は狭いフィールドよりもむしろ広いフィールドを使用することを推奨する。たとえば、その順序(例として、しばしば最初に名前と呼ばれる)で、指定された名前と姓を持つように一部の欧米文化で一般的であるが、多くの文化では、最初の家族の名前を入れて、与えられた名前2番目に、および他の多くは、単に1つの名前を(mononym)を持つ。したがって、単一のフィールドを持つことは、より柔軟性がある。

一部のフィールドは、特定のフォームコントロールに適している。コントロールが、次の表でオートフィルフィールドを記述した最初の行の5列目でオートフィルフィールドにリストされたグループに属していない場合、オートフィルフィールド名は、コントロールには不適当である。 どのようなコントロールが各グループに分類されるかは、下記の表に記載される。

フィールド名意味標準的なフォーマット標準的なフォーマット例コントロールグループ
"name"フルネーム自由形式テキスト、改行なしSir Timothy John Berners-Lee, OM, KBE, FRS, FREng, FRSAテキスト
"honorific-prefix"敬称または称号(たとえば、"Mr."、"Ms."、"Dr."、"Mlle")自由形式テキスト、改行なしSirテキスト
"given-name"Given name(一部の西洋文化において、first nameとして知られる)自由形式テキスト、改行なしTimothyテキスト
"additional-name"Additional names(一部の西洋文化において、middle namesとして知られる)自由形式テキスト、改行なしJohnテキスト
"family-name"Family name(一部の西洋文化において、last nameまたはsurnameとして知られる)自由形式テキスト、改行なしBerners-Leeテキスト
"honorific-suffix"接頭辞(たとえば、"Jr."、"B.Sc."、"MBASW"、"II")自由形式テキスト、改行なしOM, KBE, FRS, FREng, FRSAテキスト
"nickname"ニックネーム、スクリーンネーム、ハンドル:フルネームの代わりに使用する一般的に短い名前自由形式テキスト、改行なしTimテキスト
"organization-title"職種(たとえば"Software Engineer"、"Senior Vice President"、"Deputy Managing Director")自由形式テキスト、改行なしProfessorテキスト
"username"ユーザー名自由形式テキスト、改行なしtimblUsername
"new-password"新しいパスワード(たとえば、アカウントの作成またはパスワードの変更の場合)自由形式テキスト、改行なしGUMFXbadyrS3Password
"current-password"usernameフィールドによって識別されるアカウントに対する現在のパスワード(たとえば、ログイン時)自由形式テキスト、改行なしqwertyPassword
"one-time-code"ユーザーの身元を確認するために使用されるワンタイムコード自由形式テキスト、改行なし123456Password
"organization"人、アドレス、またはこのフィールドに関連付けられた他のフィールドの連絡先情報に対応する会社名自由形式テキスト、改行なしWorld Wide Web Consortiumテキスト
"street-address"所在地住所(複数行、改行を保持)自由形式テキスト32 Vassar Street
MIT Room 32-G524
Multiline
"address-line1"所在地住所(フィールドごとに1行)自由形式テキスト、改行なし32 Vassar Streetテキスト
"address-line2"自由形式テキスト、改行なしMIT Room 32-G524テキスト
"address-line3"自由形式テキスト、改行なしテキスト
"address-level4"4つの行政レベルでの住所の中で、最もきめ細かい行政レベル自由形式テキスト、改行なしテキスト
"address-level3"3つ以上の行政レベルの住所で、第3行政レベル自由形式テキスト、改行なしテキスト
"address-level2"2つ以上の管理レベルの住所で、第2行政レベル。2つの行政レベルをもつ国で、これは通常、関連する所在地住所が見つけられる、市、町、村、または他の地方になる自由形式テキスト、改行なしCambridgeテキスト
"address-level1"住所で最も広範な行政レベル、すなわち位置関係が発見される中の地方。たとえば、アメリカで、これは州(state)になる。スイスで州(canton)になる。英国で、郵便町(post town)になる。自由形式テキスト、改行なしMAテキスト
"country"国コード妥当なISO 3166-1-alpha-2国コード [ISO3166]USテキスト
"country-name"国名自由形式テキスト、改行なし。一部の場合でcountry由来USテキスト
"postal-code"郵便番号、ZIPコード、CEDEXコード(CEDEXの場合に"CEDEX"を、かつ関連する場合にを、address-level2フィールドに追加する)自由形式テキスト、改行なし02139テキスト
"cc-name"決済手段に与えられるようなフルネーム自由形式テキスト、改行なしTim Berners-Leeテキスト
"cc-given-name"決済手段に与えられるようなGiven name (一部の西洋文化において、first nameとして知られる)自由形式テキスト、改行なしTimテキスト
"cc-additional-name"決済手段に与えられるようなAdditional names(一部の西洋文化において、middle namesとして知られる)自由形式テキスト、改行なしテキスト
"cc-family-name"決済手段に与えられるようなFamily name (一部の西洋文化において、last nameまたはsurnameとして知られる)自由形式テキスト、改行なしBerners-Leeテキスト
"cc-number"決済手段(たとえばクレジットカード番号)を識別するコードASCII数字4114360123456785テキスト
"cc-exp"決済手段の有効期限妥当な月文字列2014-12Month
"cc-exp-month"決済手段の有効期限の月コンポーネント1から12までの範囲で妥当な整数12Numeric
"cc-exp-year"決済手段の有効期限の年コンポーネント0より大きい妥当な整数2014Numeric
"cc-csc"決済手段のセキュリティコード(カードのセキュリティコード(CSC)、カード検証コード(CVC)、カード検証値(CVV)、署名欄コード(SPC)、クレジットカードID(CCID)などとして知られている)ASCII数字419テキスト
"cc-type"決済手段の種類自由形式テキスト、改行なしVisaテキスト
"transaction-currency"ユーザーが取引に使用を希望する通貨ISO 4217通貨コード[ISO4217]GBPテキスト
"transaction-amount"(たとえば、ビッドまたは販売価格を入力するときに)ユーザーが取引に望む金額妥当な浮動小数点数401.00Numeric
"language"優先言語妥当なBCP 47言語タグ[BCP47]jaテキスト
"bday"誕生日妥当な日付文字列1955-06-08Date
"bday-day"誕生日の日コンポーネント1から31までの範囲で妥当な整数8Numeric
"bday-month"誕生日の月コンポーネント1から12までの範囲で妥当な整数6Numeric
"bday-year"誕生日の年コンポーネント0より大きい妥当な整数1955Numeric
"sex"性別認識(たとえば、女性、ファファフィネ)自由形式テキスト、改行なしMaleテキスト
"url"会社、人、アドレス、またはこのフィールドに関連付けられる他のフィールドでの連絡先情報に対応するホームページまたは他のウェブページ妥当なURL文字列https://www.w3.org/People/Berners-Lee/URL
"photo"会社、人、アドレス、またはこのフィールドに関連付けられる他のフィールドの連絡先情報に対応する、写真、アイコンまたは他の画像妥当なURL文字列https://www.w3.org/Press/Stock/Berners-Lee/2001-europaeum-eighth.jpgURL
"tel"国コードを含む完全な電話番号ASCII数字およびU+0020 SPACE characters、接頭辞としてU+002B PLUS SIGN文字(+)+1 617 253 5702Tel
"tel-country-code"電話番号の国コードコンポーネントASCII数字、接頭辞としてU+002B PLUS SIGN文字(+)+1テキスト
"tel-national"適用される場合は国の内部の接頭辞とともに、国コードコンポーネントなしの電話番号ASCII数字およびU+0020 SPACE characters617 253 5702テキスト
"tel-area-code"適用される場合は国の内部の接頭辞とともに、電話番号のエリアコードコンポーネントASCII数字617テキスト
"tel-local"国コードと市外局番コンポーネントなしの電話番号ASCII数字2535702テキスト
"tel-local-prefix"コンポーネントが2つのコンポーネントに分割される場合に、市外局番に続く電話番号のコンポーネントの最初の部分ASCII数字253テキスト
"tel-local-suffix"コンポーネントが2つのコンポーネントに分割される場合に、市外局番に続く電話番号のコンポーネントの2番目の部分ASCII数字5702テキスト
"tel-extension"電話番号の内部拡張コードASCII数字1000テキスト
"email"電子メールアドレス妥当な電子メールアドレスtimbl@w3.orgUsername
"impp"インスタントメッセージングプロトコルのエンドポイントを表すURL(たとえば、"aim:goim?screenname=example"またはxmpp:fred@example.net")妥当なURL文字列irc://example.org/timbl,isuserURL

次のようにグループがコントロールに対応する:

テキスト
Hidden状態のtype属性をもつinput要素
type属性がText状態であるinput要素
type属性がSearch状態であるinput要素
textarea要素
select要素
Multiline
Hidden状態のtype属性をもつinput要素
textarea要素
select要素
Password
Hidden状態のtype属性をもつinput要素
type属性がText状態であるinput要素
type属性がSearch状態であるinput要素
Password状態のtype属性をもつinput要素
textarea要素
select要素
URL
Hidden状態のtype属性をもつinput要素
type属性がText状態であるinput要素
type属性がSearch状態であるinput要素
type属性がURL状態であるinput要素
textarea要素
select要素
Username
Hidden状態のtype属性をもつinput要素
type属性がText状態であるinput要素
type属性がSearch状態であるinput要素
Email状態のtype属性をもつinput要素
textarea要素
select要素
Tel
Hidden状態のtype属性をもつinput要素
type属性がText状態であるinput要素
type属性がSearch状態であるinput要素
type属性がTelephone状態であるinput要素
textarea要素
select要素
Numeric
Hidden状態のtype属性をもつinput要素
type属性がText状態であるinput要素
type属性がSearch状態であるinput要素
Number状態のtype属性をもつinput要素
textarea要素
select要素
Month
Hidden状態のtype属性をもつinput要素
type属性がText状態であるinput要素
type属性がSearch状態であるinput要素
Month状態のtype属性をもつinput要素
textarea要素
select要素
Date
Hidden状態のtype属性をもつinput要素
type属性がText状態であるinput要素
type属性がSearch状態であるinput要素
Date状態のtype属性をもつinput要素
textarea要素
select要素

住所レベルaddress-level1" – "address-level4"フィールドは、住所の場所を記述するために使用される。異なるロケールは、異なるレベルの数を持つ。たとえば、アメリカは2つのレベル(州および町)を使用し、イギリスは、住所に応じて1つまたは2つ(郵便町、場合によっては地域)を使用し、中国は3つ(県、市、区)を使用することができる。"address-level1"フィールドは、最も広い行政区分を表す。異なるロケールは異なる方法でフィールドを順序づける。たとえば、アメリカの町(レベル2)は、州(レベル1)に先行して使用する。一方日本において都道府県(レベル1)は、地区(レベル3)に先行する市(レベル2)に先行する。著者は、(ユーザーが国を変えるのに応じてフィールドを隠す、表示するおよび再配置する)国の慣習と一致する方法で提示された形態を提供することを勧める。

4.10.18.7.2 Processing model

Each input element to which the autocomplete attribute applies, each select element, and each textarea element, has an autofill hint set, an autofill scope, an autofill field name, a non-autofill credential type, and an IDL-exposed autofill value.

The autofill field name specifies the specific kind of data expected in the field, e.g. "street-address" or "cc-exp".

The autofill hint set identifies what address or contact information type the user agent is to look at, e.g. "shipping fax" or "billing".

The non-autofill credential type identifies a type of credential that may be offered by the user agent when the user interacts with the field alongside other autofill field values. If this value is "webauthn" instead of null, selecting a credential of that type will resolve a pending conditional mediation navigator.credentials.get() request, instead of autofilling the field.

For example, a sign-in page could instruct the user agent to either autofill a saved password, or show a public key credential that will resolve a pending navigator.credentials.get() request. A user can select either to sign-in.

<input name=password type=password autocomplete="current-password webauthn">

The autofill scope identifies the group of fields whose information concerns the same subject, and consists of the autofill hint set with, if applicable, the "section-*" prefix, e.g. "billing", "section-parent shipping", or "section-child shipping home".

These values are defined as the result of running the following algorithm:

  1. If the element has no autocomplete attribute, then jump to the step labeled default.

  2. Let tokens be the result of splitting the attribute's value on ASCII whitespace.

  3. If tokens is empty, then jump to the step labeled default.

  4. Let index be the index of the last token in tokens.

  5. Let field be the indexth token in tokens.

  6. Set the category, maximum tokens pair to the result of determining a field's category given field.

  7. If category is null, then jump to the step labeled default.

  8. If the number of tokens in tokens is greater than maximum tokens, then jump to the step labeled default.

  9. If category is Off or Automatic but the element's autocomplete attribute is wearing the autofill anchor mantle, then jump to the step labeled default.

  10. If category is Off, let the element's autofill field name be the string "off", let its autofill hint set be empty, and let its IDL-exposed autofill value be the string "off". Then, return.

  11. If category is Automatic, let the element's autofill field name be the string "on", let its autofill hint set be empty, and let its IDL-exposed autofill value be the string "on". Then, return.

  12. Let scope tokens be an empty list.

  13. Let hint tokens be an empty set.

  14. Let credential type be null.

  15. Let IDL value have the same value as field.

  16. If category is Credential and the indexth token in tokens is an ASCII case-insensitive match for "webauthn", then run the substeps that follow:

    1. Set credential type to "webauthn".

    2. If the indexth token in tokens is the first entry, then skip to the step labeled done.

    3. Decrement index by one.

    4. Set the category, maximum tokens pair to the result of determining a field's category given the indexth token in tokens.

    5. If category is not Normal and category is not Contact, then jump to the step labeled default.

    6. If index is greater than maximum tokens minus one (i.e. if the number of remaining tokens is greater than maximum tokens), then jump to the step labeled default.

    7. Set IDL value to the concatenation of the indexth token in tokens, a U+0020 SPACE character, and the previous value of IDL value.

  17. If the indexth token in tokens is the first entry, then skip to the step labeled done.

  18. Decrement index by one.

  19. If category is Contact and the indexth token in tokens is an ASCII case-insensitive match for one of the strings in the following list, then run the substeps that follow:

    The substeps are:

    1. Let contact be the matching string from the list above.

    2. Insert contact at the start of scope tokens.

    3. Add contact to hint tokens.

    4. Let IDL value be the concatenation of contact, a U+0020 SPACE character, and the previous value of IDL value.

    5. If the indexth entry in tokens is the first entry, then skip to the step labeled done.

    6. Decrement index by one.

  20. If the indexth token in tokens is an ASCII case-insensitive match for one of the strings in the following list, then run the substeps that follow:

    The substeps are:

    1. Let mode be the matching string from the list above.

    2. Insert mode at the start of scope tokens.

    3. Add mode to hint tokens.

    4. Let IDL value be the concatenation of mode, a U+0020 SPACE character, and the previous value of IDL value.

    5. If the indexth entry in tokens is the first entry, then skip to the step labeled done.

    6. Decrement index by one.

  21. If the indexth entry in tokens is not the first entry, then jump to the step labeled default.

  22. If the first eight characters of the indexth token in tokens are not an ASCII case-insensitive match for the string "section-", then jump to the step labeled default.

  23. Let section be the indexth token in tokens, converted to ASCII lowercase.

  24. Insert section at the start of scope tokens.

  25. Let IDL value be the concatenation of section, a U+0020 SPACE character, and the previous value of IDL value.

  26. Done: Let the element's autofill hint set be hint tokens.

  27. Let the element's non-autofill credential type be credential type.

  28. Let the element's autofill scope be scope tokens.

  29. Let the element's autofill field name be field.

  30. Let the element's IDL-exposed autofill value be IDL value.

  31. Return.

  32. Default: Let the element's IDL-exposed autofill value be the empty string, and its autofill hint set and autofill scope be empty.

  33. If the element's autocomplete attribute is wearing the autofill anchor mantle, then let the element's autofill field name be the empty string and return.

  34. Let form be the element's form owner, if any, or null otherwise.

  35. If form is not null and form's autocomplete attribute is in the off state, then let the element's autofill field name be "off".

    Otherwise, let the element's autofill field name be "on".

To determine a field's category, given field:

  1. If the field is not an ASCII case-insensitive match for one of the tokens given in the first column of the following table, return the pair (null, null).

    TokenMaximum number of tokensカテゴリー
    "off"1Off
    "on"1Automatic
    "name"3Normal
    "honorific-prefix"3Normal
    "given-name"3Normal
    "additional-name"3Normal
    "family-name"3Normal
    "honorific-suffix"3Normal
    "nickname"3Normal
    "organization-title"3Normal
    "username"3Normal
    "new-password"3Normal
    "current-password"3Normal
    "one-time-code"3Normal
    "organization"3Normal
    "street-address"3Normal
    "address-line1"3Normal
    "address-line2"3Normal
    "address-line3"3Normal
    "address-level4"3Normal
    "address-level3"3Normal
    "address-level2"3Normal
    "address-level1"3Normal
    "country"3Normal
    "country-name"3Normal
    "postal-code"3Normal
    "cc-name"3Normal
    "cc-given-name"3Normal
    "cc-additional-name"3Normal
    "cc-family-name"3Normal
    "cc-number"3Normal
    "cc-exp"3Normal
    "cc-exp-month"3Normal
    "cc-exp-year"3Normal
    "cc-csc"3Normal
    "cc-type"3Normal
    "transaction-currency"3Normal
    "transaction-amount"3Normal
    "language"3Normal
    "bday"3Normal
    "bday-day"3Normal
    "bday-month"3Normal
    "bday-year"3Normal
    "sex"3Normal
    "url"3Normal
    "photo"3Normal
    "tel"4Contact
    "tel-country-code"4Contact
    "tel-national"4Contact
    "tel-area-code"4Contact
    "tel-local"4Contact
    "tel-local-prefix"4Contact
    "tel-local-suffix"4Contact
    "tel-extension"4Contact
    "email"4Contact
    "impp"4Contact
    "webauthn"5Credential
  2. Otherwise, let maximum tokens and category be the values of the cells in the second and third columns of that row respectively.

  3. Return the pair (category, maximum tokens).


For the purposes of autofill, a control's data depends on the kind of control:

An input element with its type attribute in the Email state and with the multiple attribute specified
The element's values.
Any other input element
A textarea element
The element's value.
A select element with its multiple attribute specified
The option elements in the select element's list of options that have their selectedness set to true.
Any other select element
The option element in the select element's list of options that has its selectedness set to true.

How to process the autofill hint set, autofill scope, and autofill field name depends on the mantle that the autocomplete attribute is wearing.

オートフィル予想マント着用時は

When an element's autofill field name is "off", the user agent should not remember the control's data, and should not offer past values to the user.

In addition, when an element's autofill field name is "off", values are reset when reactivating a document.

Banks frequently do not want UAs to prefill login information:

<p><label>Account: <input type="text" name="ac" autocomplete="off"></label></p>
<p><label>PIN: <input type="password" name="pin" autocomplete="off"></label></p>

When an element's autofill field name is not "off", the user agent may store the control's data, and may offer previously stored values to the user.

For example, suppose a user visits a page with this control:

<select name="country">
 <option>Afghanistan
 <option>Albania
 <option>Algeria
 <option>Andorra
 <option>Angola
 <option>Antigua and Barbuda
 <option>Argentina
 <option>Armenia
 <!-- ... -->
 <option>Yemen
 <option>Zambia
 <option>Zimbabwe
</select>

これは次のようにレンダリングされるだろう:

A drop-down control with a long alphabetical list of countries.

Suppose that on the first visit to this page, the user selects "Zambia". On the second visit, the user agent could duplicate the entry for Zambia at the top of the list, so that the interface instead looks like this:

The same drop-down control with the alphabetical list of countries, but with Zambia as an entry at the top.

When the autofill field name is "on", the user agent should attempt to use heuristics to determine the most appropriate values to offer the user, e.g. based on the element's name value, the position of the element in its tree, what other fields exist in the form, and so forth.

オートフィルフィールド名が上記のオートフィルフィールドの名前のいずれかに該当する場合、ユーザーエージェントは、以前のこのセクションの表に示すようなフィールド名の意味と一致する提案を提供すべきである。オートフィルのヒントセットは複数の可能な提案の中で選択するために使用されるべきである。

たとえば、ユーザーが一度 "shipping"キーワードを使用するフィールドにアドレスを入力し、"billing" キーワードを使用するフィールドに別のアドレスを入力した場合、後続で、オートフィルヒントがキーワード"shipping"を含むフォームコントロールに提案されるだろう最初のアドレスのみを構成する。しかし、 両方のアドレスは、オートフィルヒントセットがいずれかのキーワードが含まないアドレスに関連したフォームコントロールに対して提案されるかもしれない。

オートフィルアンカーマントを着用時

When the autofill field name is not the empty string, then the user agent must act as if the user had specified the control's data for the given autofill hint set, autofill scope, and autofill field name combination.

When the user agent autofills form controls, elements with the same form owner and the same autofill scope must use data relating to the same person, address, payment instrument, and contact details. When a user agent autofills "country" and "country-name" fields with the same form owner and autofill scope, and the user agent has a value for the country" field(s), then the "country-name" field(s) must be filled using a human-readable name for the same country. When a user agent fills in multiple fields at once, all fields with the same autofill field name, form owner and autofill scope must be filled with the same value.

ユーザーエージェントが2つの電話番号、+1 555 123 1234および+1 555 666 7777を知っていると仮定する。値"123"をとともにautocomplete="shipping tel-local-prefix"を持つフィールド、および値"7777"とともにautocomplete="shipping tel-local-suffix"を持つ同じフォームの別のフィールドを埋めることはユーザーエージェントに対して適合しないだろう。前述の情報が指定される唯一の妥当な事前入力値は、それぞれ、"123"と"1234"、または"666"と"7777"となる。

同様に、ある理由でフォームがcc-exp"フィールドと"cc-exp-month"フィールドの両方を含む、およびユーザーエージェントがフォームを事前入力する場合、前者の月コンポーネントは後者と一致する必要があるだろう。

This requirement interacts with the autofill anchor mantle also. 次のマークアップ断片を考えてみよう:

<form>
 <input type=hidden autocomplete="nickname" value="TreePlate">
 <input type=text autocomplete="nickname">
</form>

The only value that a conforming user agent could suggest in the text control is "TreePlate", the value given by the hidden input element.

The "section-*" tokens in the autofill scope are opaque; user agents must not attempt to derive meaning from the precise values of these tokens.

For example, it would not be conforming if the user agent decided that it should offer the address it knows to be the user's daughter's address for "section-child" and the addresses it knows to be the user's spouses' addresses for "section-spouse".

The autocompletion mechanism must be implemented by the user agent acting as if the user had modified the control's data, and must be done at a time where the element is mutable (e.g. just after the element has been inserted into the document, or when the user agent stops parsing). ユーザーエージェントは、は、ユーザーが入力したかもしれない値を使用するコントロールのみを事前入力しなければならない。

たとえば、select要素が、値"Steve"、"Rebecca"、"Jay"、"Bob"をもつoption要素のみを持ち、かつオートフィルフィールド名"given-name"を持つが、フィールドを事前入力が"Evan"であるようなユーザーエージェントのアイデアのみである場合、ユーザーエージェントは、フィールドを事前入力できない。ユーザーが自分自身を行っていることができなかったので、何らかの形で値"Evan"にselect要素を設定することは適合しないだろう。

A user agent prefilling a form control must not discriminate between form controls that are in a document tree and those that are connected; that is, it is not conforming to make the decision on whether or not to autofill based on whether the element's root is a shadow root versus a Document.

A user agent prefilling a form control's value must not cause that control to suffer from a type mismatch, suffer from being too long, suffer from being too short, suffer from an underflow, suffer from an overflow, or suffer from a step mismatch. A user agent prefilling a form control's value must not cause that control to suffer from a pattern mismatch either. Where possible given the control's constraints, user agents must use the format given as canonical in the aforementioned table. Where it's not possible for the canonical format to be used, user agents should use heuristics to attempt to convert values so that they can be used.

たとえば、ユーザーエージェントがユーザーのミドルネームが"Ines"であり、フォームコントロールを事前入力しようとする試みる場合、このようになる:

<input name=middle-initial maxlength=1 autocomplete="additional-name">

ユーザーエージェントは"I"を"Ines"に変換し、このように事前入力できるだろう。

より複雑な例では、月の値となる。ユーザーエージェントが、ユーザーの誕生日が2012年7月27日であることを知っている場合、わずかに異なる値を持つ以下のコントロールのすべてを事前入力しよう試み、この情報から駆動する。

<input name=b type=month autocomplete="bday">
2012-07状態が月/年の組み合わせのみを受け入れるので、日は破棄される。(Note that this example is non-conforming, because the autofill field name bday is not allowed with the Month state.)
<select name=c autocomplete="bday">
 <option>Jan
 <option>Feb
 ...
 <option>Jul
 <option>Aug
 ...
</select>
JulyThe user agent picks the month from the listed options, either by noticing there are twelve options and picking the 7th, or by recognizing that one of the strings (three characters "Jul" followed by a newline and a space) is a close match for the name of the month (July) in one of the user agent's supported languages, or through some other similar mechanism.
<input name=a type=number min=1 max=12 autocomplete="bday-month">
7ユーザーエージェントは、フィールドのように、範囲1から12の数字を"July"に変換する。
<input name=a type=number min=0 max=11 autocomplete="bday-month">
6ユーザーエージェントは、フィールドのように、範囲0から11の数字を"July"に変換する。
<input name=a type=number min=1 max=11 autocomplete="bday-month">
フォームが期待するものとして良い推測ができないため、ユーザーエージェントはフィールドに入力しない。

ユーザーエージェントは、ユーザーが要素のオートフィルフィールド名を上書き可能にしてもよい。たとえばページの作成者の異議にもかかわらず記憶されるおよび事前に入力されるよう許可するために"off"から"on"に変更すること、または値を記憶しないよう常に"off"にするなど。

More specifically, user agents may in particular consider replacing the autofill field name of form controls that match the description given in the first column of the following table, when their autofill field name is either "on" or "off", with the value given in the second cell of that row. If this table is used, the replacements must be done in tree order, since all but the first row references the autofill field name of earlier elements. When the descriptions below refer to form controls being preceded or followed by others, they mean in the list of listed elements that share the same form owner.

フォームのコントロールNew autofill field name
an input element whose type attribute is in the Text state that is followed by an input element whose type attribute is in the Password state"username"
an input element whose type attribute is in the Password state that is preceded by an input element whose autofill field name is "username""current-password"
an input element whose type attribute is in the Password state that is preceded by an input element whose autofill field name is "current-password""new-password"
an input element whose type attribute is in the Password state that is preceded by an input element whose autofill field name is "new-password""new-password"

autocomplete IDL属性は、取得時に、要素のIDL公開オートフィル値を返さなければならず、設定時に、同じ名前のコンテンツ属性を反映しなければならない。

4.10.19 テキストフィールド選択のためのAPI

input要素とtextarea要素は、それらの選択を処理するための複数の属性およびメソッドを定義する。共有アルゴリズムはここで定義される。

element.select()

テキストコントロールにおけるすべてを選択する。

element.selectionStart [ = value ]

セレクションの開始オフセットを返す。

セレクションの開始を変更する設定が可能である。

element.selectionEnd [ = value ]

セレクションの終了オフセットを返す。

セレクションの終了を変更する設定が可能である。

element.selectionDirection [ = value ]

セレクションの現在の方向を返す。

セレクションの現在の方向を変更する設定が可能である。

可能な値は、"forward"、"backward"、"none"である。

element.setSelectionRange(start, end [, direction])

HTMLInputElement/setSelectionRange

Support in all current engines.

Firefox1+Safari3+Chrome1+
Opera8+Edge79+
Edge (Legacy)12+Internet Explorer9+
Firefox Android?Safari iOS1+Chrome Android?WebView Android?Samsung Internet?Opera Android10.1+

指定された方向に指定された部分列をカバーするために選択を変更する。方向が省略された場合、方向がプラットフォームのデフォルト(なしまたは前方)になるようにリセットされる。

element.setRangeText(replacement [, start, end [, selectionMode ] ])

HTMLInputElement/setRangeText

Support in all current engines.

Firefox27+Safari7+Chrome24+
Opera?Edge79+
Edge (Legacy)?Internet ExplorerNo
Firefox Android?Safari iOS?Chrome Android?WebView Android?Samsung Internet?Opera Android?

新しいテキストとともにテキストの範囲を置換する。startおよびend引数が提供されない場合、範囲は選択されることが想定される。

最後の引数は、テキストを交換した後に選択が設定されるかを決定する。可能な値は次のとおり:

"select"
新しく挿入されたテキストを選択する。
"start"
挿入されたテキストの前のアイテムのみを選択する。
"end"
選択されたテキストの後のアイテムのみを選択する。
"preserve"
選択を保持しようとする。これはデフォルトである。

All input elements to which these APIs apply, and all textarea elements, have either a selection or a text entry cursor position at all times (even for elements that are not being rendered), measured in offsets into the code units of the control's relevant value. The initial state must consist of a text entry cursor at the beginning of the control.

For input elements, these APIs must operate on the element's value. For textarea elements, these APIs must operate on the element's API value. In the below algorithms, we call the value string being operated on the relevant value.

The use of API value instead of raw value for textarea elements means that U+000D (CR) characters are normalized away. For example,

<textarea id="demo"></textarea>
<script>
 demo.value = "A\r\nB";
 demo.setRangeText("replaced", 0, 2);
 assert(demo.value === "replacedB");
</script>

If we had operated on the raw value of "A\r\nB", then we would have replaced the characters "A\r", ending up with a result of "replaced\nB". But since we used the API value of "A\nB", we replaced the characters "A\n", giving "replacedB".

U+200D ZERO WIDTH JOINERのような、不可視のレンダリングをともなう文字は、依然として文字としてカウントされる。したがって、たとえば選択は単に不可視の文字を含めることができ、テキスト挿入カーソルは片側またはそのような文字の別のものに配置できる。

Whenever the relevant value changes for an element to which these APIs apply, run these steps:

  1. If the element has a selection:

    1. If the start of the selection is now past the end of the relevant value, set it to the end of the relevant value.

    2. If the end of the selection is now past the end of the relevant value, set it to the end of the relevant value.

    3. If the user agent does not support empty selection, and both the start and end of the selection are now pointing to the end of the relevant value, then instead set the element's text entry cursor position to the end of the relevant value, removing any selection.

  2. Otherwise, the element must have a text entry cursor position position. If it is now past the end of the relevant value, set it to the end of the relevant value.

In some cases where the relevant value changes, other parts of the specification will also modify the text entry cursor position, beyond just the clamping steps above. For example, see the value setter for textarea.

Where possible, user interface features for changing the text selection in input and textarea elements must be implemented using the set the selection range algorithm so that, e.g., all the same events fire.

The selections of input and textarea elements have a selection direction, which is either "forward", "backward", or "none". The exact meaning of the selection direction depends on the platform. This direction is set when the user manipulates the selection. The initial selection direction must be "none" if the platform supports that direction, or "forward" otherwise.

To set the selection direction of an element to a given direction, update the element's selection direction to the given direction, unless the direction is "none" and the platform does not support that direction; in that case, update the element's selection direction to "forward".

On Windows, the direction indicates the position of the caret relative to the selection: a "forward" selection has the caret at the end of the selection and a "backward" selection has the caret at the start of the selection. Windows has no "none" direction.

On Mac, the direction indicates which end of the selection is affected when the user adjusts the size of the selection using the arrow keys with the Shift modifier: the "forward" direction means the end of the selection is modified, and the "backward" direction means the start of the selection is modified. The "none" direction is the default on Mac, it indicates that no particular direction has yet been selected. The user sets the direction implicitly when first adjusting the selection, based on which directional arrow key was used.

HTMLInputElement/select

Support in all current engines.

Firefox1+Safari1+Chrome1+
Opera12.1+Edge79+
Edge (Legacy)12+Internet Explorer5.5+
Firefox Android?Safari iOS?Chrome Android?WebView Android?Samsung Internet?Opera Android12.1+

HTMLInputElement/select

The select() method, when invoked, must run the following steps:

  1. If this element is an input element, and either select() does not apply to this element or the corresponding control has no selectable text, return.

    For instance, in a user agent where <input type=color> is rendered as a color well with a picker, as opposed to a text control accepting a hexadecimal color code, there would be no selectable text, and thus calls to the method are ignored.

  2. Set the selection range with 0 and infinity.

The selectionStart attribute's getter must run the following steps:

  1. If this element is an input element, and selectionStart does not apply to this element, return null.

  2. If there is no selection, return the code unit offset within the relevant value to the character that immediately follows the text entry cursor.

  3. Return the code unit offset within the relevant value to the character that immediately follows the start of the selection.

The selectionStart attribute's setter must run the following steps:

  1. If this element is an input element, and selectionStart does not apply to this element, throw an "InvalidStateError" DOMException.

  2. Let end be the value of this element's selectionEnd attribute.

  3. If end is less than the given value, set end to the given value.

  4. Set the selection range with the given value, end, and the value of this element's selectionDirection attribute.

The selectionEnd attribute's getter must run the following steps:

  1. If this element is an input element, and selectionEnd does not apply to this element, return null.

  2. If there is no selection, return the code unit offset within the relevant value to the character that immediately follows the text entry cursor.

  3. Return the code unit offset within the relevant value to the character that immediately follows the end of the selection.

The selectionEnd attribute's setter must run the following steps:

  1. If this element is an input element, and selectionEnd does not apply to this element, throw an "InvalidStateError" DOMException.

  2. Set the selection range with the value of this element's selectionStart attribute, the given value, and the value of this element's selectionDirection attribute.

The selectionDirection attribute's getter must run the following steps:

  1. If this element is an input element, and selectionDirection does not apply to this element, return null.

  2. Return this element's selection direction.

The selectionDirection attribute's setter must run the following steps:

  1. If this element is an input element, and selectionDirection does not apply to this element, throw an "InvalidStateError" DOMException.

  2. Set the selection range with the value of this element's selectionStart attribute, the value of this element's selectionEnd attribute, and the given value.

The setSelectionRange(start, end, direction) method, when invoked, must run the following steps:

  1. If this element is an input element, and setSelectionRange() does not apply to this element, throw an "InvalidStateError" DOMException.

  2. Set the selection range with start, end, and direction.

To set the selection range with an integer or null start, an integer or null or the special value infinity end, and optionally a string direction, run the following steps:

  1. If start is null, let start be zero.

  2. If end is null, let end be zero.

  3. Set the selection of the text control to the sequence of code units within the relevant value starting with the code unit at the startth position (in logical order) and ending with the code unit at the (end-1)th position. Arguments greater than the length of the relevant value of the text control (including the special value infinity) must be treated as pointing at the end of the text control. If end is less than or equal to start then the start of the selection and the end of the selection must both be placed immediately before the character with offset end. In UAs where there is no concept of an empty selection, this must set the cursor to be just before the character with offset end.

  4. If direction is not identical to either "backward" or "forward", or if the direction argument was not given, set direction to "none".

  5. Set the selection direction of the text control to direction.

  6. If the previous steps caused the selection of the text control to be modified (in either extent or direction), then queue an element task on the user interaction task source given the element to fire an event named select at the element, with the bubbles attribute initialized to true.

The setRangeText(replacement, start, end, selectMode) method, when invoked, must run the following steps:

  1. If this element is an input element, and setRangeText() does not apply to this element, throw an "InvalidStateError" DOMException.

  2. Set this element's dirty value flag to true.

  3. If the method has only one argument, then let start and end have the values of the selectionStart attribute and the selectionEnd attribute respectively.

    Otherwise, let start, end have the values of the second and third arguments respectively.

  4. If start is greater than end, then throw an "IndexSizeError" DOMException.

  5. If start is greater than the length of the relevant value of the text control, then set it to the length of the relevant value of the text control.

  6. If end is greater than the length of the relevant value of the text control, then set it to the length of the relevant value of the text control.

  7. Let selection start be the current value of the selectionStart attribute.

  8. Let selection end be the current value of the selectionEnd attribute.

  9. If start is less than end, delete the sequence of code units within the element's relevant value starting with the code unit at the startth position and ending with the code unit at the (end-1)th position.

  10. Insert the value of the first argument into the text of the relevant value of the text control, immediately before the startth code unit.

  11. Let new length be the length of the value of the first argument.

  12. Let new end be the sum of start and new length.

  13. Run the appropriate set of substeps from the following list:

    If the fourth argument's value is "select"

    Let selection start be start.

    Let selection end be new end.

    If the fourth argument's value is "start"

    Let selection start and selection end be start.

    If the fourth argument's value is "end"

    Let selection start and selection end be new end.

    If the fourth argument's value is "preserve"
    If the method has only one argument
    1. Let old length be end minus start.

    2. Let delta be new length minus old length.

    3. If selection start is greater than end, then increment it by delta. (If delta is negative, i.e. the new text is shorter than the old text, then this will decrease the value of selection start.)

      Otherwise: if selection start is greater than start, then set it to start. (This snaps the start of the selection to the start of the new text if it was in the middle of the text that it replaced.)

    4. If selection end is greater than end, then increment it by delta in the same way.

      Otherwise: if selection end is greater than start, then set it to new end. (This snaps the end of the selection to the end of the new text if it was in the middle of the text that it replaced.)

  14. Set the selection range with selection start and selection end.

The setRangeText() method uses the following enumeration:

enum SelectionMode {
  "select",
  "start",
  "end",
  "preserve" // default
};

現在選択されているテキストを取得するためには、次のJavaScriptで十分である:

var selectionText = control.value.substring(control.selectionStart, control.selectionEnd);

ここで、controlinputまたはtextarea要素である。

テキストの選択範囲を維持する一方で、テキストコントロールの開始時にテキストを追加するには、3つの属性が保持されなければならない:

var oldStart = control.selectionStart;
var oldEnd = control.selectionEnd;
var oldDirection = control.selectionDirection;
var prefix = "http://";
control.value = prefix + control.value;
control.setSelectionRange(oldStart + prefix.length, oldEnd + prefix.length, oldDirection);

ここで、controlinputまたはtextarea要素である。

4.10.20 制約

4.10.20.1 定義

A submittable element is a candidate for constraint validation except when a condition has barred the element from constraint validation. (For example, an element is barred from constraint validation if it has a datalist element ancestor.)

An element can have a custom validity error message defined. Initially, an element must have its custom validity error message set to the empty string. When its value is not the empty string, the element is suffering from a custom error. It can be set using the setCustomValidity() method, except for form-associated custom elements. Form-associated custom elements can have a custom validity error message set via their ElementInternals object's setValidity() method. The user agent should use the custom validity error message when alerting the user to the problem with the control.

An element can be constrained in various ways. The following is the list of validity states that a form control can be in, making the control invalid for the purposes of constraint validation. (The definitions below are non-normative; other parts of this specification define more precisely when each state applies or does not.)

Suffering from being missing

When a control has no value but has a required attribute (input required, textarea required); or, more complicated rules for select elements and controls in radio button groups, as specified in their sections.

When the setValidity() method sets valueMissing flag to true for a form-associated custom element.

Suffering from a type mismatch

When a control that allows arbitrary user input has a value that is not in the correct syntax (Email, URL).

When the setValidity() method sets typeMismatch flag to true for a form-associated custom element.

Suffering from a pattern mismatch

When a control has a value that doesn't satisfy the pattern attribute.

When the setValidity() method sets patternMismatch flag to true for a form-associated custom element.

Suffering from being too long

When a control has a value that is too long for the form control maxlength attribute (input maxlength, textarea maxlength).

When the setValidity() method sets tooLong flag to true for a form-associated custom element.

Suffering from being too short

When a control has a value that is too short for the form control minlength attribute (input minlength, textarea minlength).

When the setValidity() method sets tooShort flag to true for a form-associated custom element.

Suffering from an underflow

When a control has a value that is not the empty string and is too low for the min attribute.

When the setValidity() method sets rangeUnderflow flag to true for a form-associated custom element.

Suffering from an overflow

When a control has a value that is not the empty string and is too high for the max attribute.

When the setValidity() method sets rangeOverflow flag to true for a form-associated custom element.

Suffering from a step mismatch

When a control has a value that doesn't fit the rules given by the step attribute.

When the setValidity() method sets stepMismatch flag to true for a form-associated custom element.

Suffering from bad input

When a control has incomplete input and the user agent does not think the user ought to be able to submit the form in its current state.

When the setValidity() method sets badInput flag to true for a form-associated custom element.

Suffering from a custom error

When a control's custom validity error message (as set by the element's setCustomValidity() method or ElementInternals's setValidity() method) is not the empty string.

An element can still suffer from these states even when the element is disabled; thus these states can be represented in the DOM even if validating the form during submission wouldn't indicate a problem to the user.

An element satisfies its constraints if it is not suffering from any of the above validity states.

4.10.20.2 Constraint validation

When the user agent is required to statically validate the constraints of form element form, it must run the following steps, which return either a positive result (all the controls in the form are valid) or a negative result (there are invalid controls) along with a (possibly empty) list of elements that are invalid and for which no script has claimed responsibility:

  1. Let controls be a list of all the submittable elements whose form owner is form, in tree order.

  2. Let invalid controls be an initially empty list of elements.

  3. For each element field in controls, in tree order:

    1. If field is not a candidate for constraint validation, then move on to the next element.

    2. Otherwise, if field satisfies its constraints, then move on to the next element.

    3. Otherwise, add field to invalid controls.

  4. If invalid controls is empty, then return a positive result.

  5. Let unhandled invalid controls be an initially empty list of elements.

  6. For each element field in invalid controls, if any, in tree order:

    1. Let notCanceled be the result of firing an event named invalid at field, with the cancelable attribute initialized to true.

    2. If notCanceled is true, then add field to unhandled invalid controls.

  7. Return a negative result with the list of elements in the unhandled invalid controls list.

If a user agent is to interactively validate the constraints of form element form, then the user agent must run the following steps:

  1. Statically validate the constraints of form, and let unhandled invalid controls be the list of elements returned if the result was negative.

  2. If the result was positive, then return that result.

  3. Report the problems with the constraints of at least one of the elements given in unhandled invalid controls to the user.

  4. Return a negative result.

4.10.20.3 制約検証API
element.willValidate

HTMLObjectElement/willValidate

Support in all current engines.

Firefox4+Safari5+Chrome4+
Opera12.1+Edge79+
Edge (Legacy)12+Internet Explorer10+
Firefox Android?Safari iOS4+Chrome Android?WebView Android37+Samsung Internet?Opera Android12.1+

フォームが送信されるときに要素が認証される場合trueを返し、そうでなければfalseを返す。

element.setCustomValidity(message)

HTMLObjectElement/setCustomValidity

Support in all current engines.

Firefox4+Safari5.1+Chrome10+
Opera12.1+Edge79+
Edge (Legacy)12+Internet Explorer10+
Firefox Android?Safari iOS?Chrome Android?WebView Android37+Samsung Internet?Opera Android12.1+

HTMLSelectElement/setCustomValidity

Support in all current engines.

Firefox4+Safari5+Chrome4+
Opera12.1+Edge79+
Edge (Legacy)12+Internet Explorer10+
Firefox Android?Safari iOS4+Chrome Android?WebView Android37+Samsung Internet?Opera Android12.1+

要素の検証に失敗するように、カスタムエラーを設定する。与えられたメッセージは、ユーザーに問題を報告するときにユーザーに表示されるメッセージである。

引数が空文字列である場合、カスタムエラーをクリアする。

element.validity.valueMissing

ValidityState/valueMissing

Support in all current engines.

Firefox4+Safari5+Chrome4+
Opera12.1+Edge79+
Edge (Legacy)12+Internet Explorer10+
Firefox Android?Safari iOS5+Chrome Android?WebView Android37+Samsung Internet?Opera Android12.1+

要素が値を持たないが必須フィールドである場合trueを返し、そうでなければfalseを返す。

element.validity.typeMismatch

要素の値が正しい構文でない場合trueを返し、そうでなければfalseを返す。

element.validity.patternMismatch

要素の値が提供されたパターンとマッチしない場合trueを返し、そうでなければfalseを返す。

element.validity.tooLong

ValidityState/tooLong

Support in all current engines.

Firefox4+Safari5+Chrome4+
Opera12.1+Edge79+
Edge (Legacy)12+Internet Explorer10+
Firefox Android64+Safari iOS5+Chrome Android?WebView Android4+Samsung Internet?Opera Android12.1+

要素の値が提供された最大長さより長い場合trueを返し、そうでなければfalseを返す。

element.validity.tooShort

ValidityState/tooShort

Support in all current engines.

Firefox51+Safari10+Chrome40+
Opera?Edge79+
Edge (Legacy)17+Internet ExplorerNo
Firefox Android64+Safari iOS?Chrome Android?WebView Android67+Samsung Internet?Opera Android?

要素の値が空文字列ではなく、提供された最小長さより短い場合trueを返し、そうでなければfalseを返す。

element.validity.rangeUnderflow

要素の値が提供された最小値より短い場合trueを返し、そうでなければfalseを返す。

element.validity.rangeOverflow

要素の値が提供された最大値より長い場合trueを返し、そうでなければfalseを返す。

element.validity.stepMismatch

要素の値がstep属性によって与えられる規則に合致しない場合trueを返し、そうでなければfalseを返す。

element.validity.badInput

ValidityState/badInput

Support in all current engines.

Firefox29+Safari7+Chrome25+
Opera?Edge79+
Edge (Legacy)12+Internet ExplorerNo
Firefox Android64+Safari iOS?Chrome Android?WebView Android?Samsung Internet?Opera Android?

ユーザーエージェントが値に変換できないユーザーインターフェイスで入力をユーザーが提供される場合trueを返し、そうでなければfalseを返す。

element.validity.customError

要素がカスタムエラーを持つ場合trueを返し、そうでなければfalseを返す。

element.validity.valid

要素の値が妥当性問題を持たない場合trueを返し、そうでなければfalseを返す。

valid = element.checkValidity()

HTMLInputElement/checkValidity

Support in all current engines.

Firefox4+Safari5+Chrome4+
Opera12.1+Edge79+
Edge (Legacy)12+Internet Explorer10+
Firefox Android?Safari iOS4+Chrome Android?WebView Android37+Samsung Internet?Opera Android12.1+

HTMLObjectElement/checkValidity

Support in all current engines.

Firefox4+Safari5.1+Chrome10+
Opera12.1+Edge79+
Edge (Legacy)12+Internet Explorer10+
Firefox Android?Safari iOS?Chrome Android?WebView Android37+Samsung Internet?Opera Android12.1+

HTMLSelectElement/checkValidity

Support in all current engines.

Firefox4+Safari5+Chrome4+
Opera9+Edge79+
Edge (Legacy)12+Internet Explorer10+
Firefox Android?Safari iOS4+Chrome Android?WebView Android37+Samsung Internet?Opera Android10.1+

要素の値が妥当性問題を持たない場合trueを返し、そうでなければfalseを返す。後者の場合要素でinvalidイベントを発火する。

valid = element.reportValidity()

HTMLFormElement/reportValidity

Support in all current engines.

Firefox49+Safari10.1+Chrome40+
Opera?Edge79+
Edge (Legacy)17+Internet ExplorerNo
Firefox Android?Safari iOS?Chrome Android?WebView Android?Samsung Internet?Opera Android?

HTMLInputElement/reportValidity

Support in all current engines.

Firefox49+Safari10.1+Chrome40+
Opera?Edge79+
Edge (Legacy)17+Internet ExplorerNo
Firefox Android64+Safari iOS?Chrome Android?WebView Android?Samsung Internet?Opera Android?

要素の値が一切妥当性の問題を持たない場合はtrueを返す。そうでなければfalseを返し、要素でinvalidイベントを発火させ、そして(イベントが中止されない場合)ユーザーに問題を報告する。

element.validationMessage

HTMLObjectElement/validationMessage

Support in all current engines.

Firefox4+Safari5.1+Chrome10+
Opera12.1+Edge79+
Edge (Legacy)12+Internet Explorer10+
Firefox Android?Safari iOS?Chrome Android?WebView Android37+Samsung Internet?Opera Android12.1+

要素が妥当性に対してチェックされた場合、ユーザーに表示されるエラーメッセージを返す。

The willValidate attribute's getter must return true, if this element is a candidate for constraint validation, and false otherwise (i.e., false if any conditions are barring it from constraint validation).

ElementInternals/willValidate

Support in all current engines.

Firefox98+Safari16.4+Chrome77+
Opera?Edge79+
Edge (Legacy)?Internet ExplorerNo
Firefox Android?Safari iOS?Chrome Android?WebView Android?Samsung Internet?Opera Android?

The willValidate attribute of ElementInternals interface, on getting, must throw a "NotSupportedError" DOMException if the target element is not a form-associated custom element. Otherwise, it must return true if the target element is a candidate for constraint validation, and false otherwise.

HTMLInputElement/setCustomValidity

Support in all current engines.

Firefox4+Safari5+Chrome4+
Opera12.1+Edge79+
Edge (Legacy)12+Internet Explorer10+
Firefox Android?Safari iOS4+Chrome Android?WebView Android37+Samsung Internet?Opera Android12.1+

The setCustomValidity(error) method, when invoked, must set the custom validity error message to error.

次の例において、スクリプトは値が編集されるたびにフォームコントロールの値をチェックし、かつ妥当な値でない場合はいつでも、適切なメッセージを設定するためにsetCustomValidity()メソッドを使用する。

<label>Feeling: <input name=f type="text" oninput="check(this)"></label>
<script>
 function check(input) {
   if (input.value == "good" ||
       input.value == "fine" ||
       input.value == "tired") {
     input.setCustomValidity('"' + input.value + '" is not a feeling.');
   } else {
     // input is fine -- reset the error message
     input.setCustomValidity('');
   }
 }
</script>

HTMLObjectElement/validity

Support in all current engines.

Firefox4+Safari5.1+Chrome10+
Opera12.1+Edge79+
Edge (Legacy)12+Internet Explorer10+
Firefox Android?Safari iOS?Chrome Android?WebView Android37+Samsung Internet?Opera Android12.1+

The validity attribute's getter must return a ValidityState object that represents the validity states of this element. This object is live.

ElementInternals/validity

Support in all current engines.

Firefox98+Safari16.4+Chrome77+
Opera?Edge79+
Edge (Legacy)?Internet ExplorerNo
Firefox Android?Safari iOS?Chrome Android?WebView Android?Samsung Internet?Opera Android?

The validity attribute of ElementInternals interface, on getting, must throw a "NotSupportedError" DOMException if the target element is not a form-associated custom element. Otherwise, it must return a ValidityState object that represents the validity states of the target element. This object is live.

[Exposed=Window]
interface ValidityState {
  readonly attribute boolean valueMissing;
  readonly attribute boolean typeMismatch;
  readonly attribute boolean patternMismatch;
  readonly attribute boolean tooLong;
  readonly attribute boolean tooShort;
  readonly attribute boolean rangeUnderflow;
  readonly attribute boolean rangeOverflow;
  readonly attribute boolean stepMismatch;
  readonly attribute boolean badInput;
  readonly attribute boolean customError;
  readonly attribute boolean valid;
};

A ValidityState object has the following attributes. On getting, they must return true if the corresponding condition given in the following list is true, and false otherwise.

valueMissing

The control is suffering from being missing.

typeMismatch

ValidityState/typeMismatch

Support in all current engines.

Firefox4+Safari5+Chrome4+
Opera12.1+Edge79+
Edge (Legacy)12+Internet Explorer10+
Firefox Android?Safari iOS5+Chrome Android?WebView Android37+Samsung Internet?Opera Android12.1+

The control is suffering from a type mismatch.

patternMismatch

ValidityState/patternMismatch

Support in all current engines.

Firefox4+Safari5+Chrome4+
Opera12.1+Edge79+
Edge (Legacy)12+Internet Explorer10+
Firefox Android?Safari iOS5+Chrome Android?WebView Android37+Samsung Internet?Opera Android12.1+

The control is suffering from a pattern mismatch.

tooLong

The control is suffering from being too long.

tooShort

The control is suffering from being too short.

rangeUnderflow

ValidityState/rangeUnderflow

Support in all current engines.

Firefox4+Safari5+Chrome4+
Opera12.1+Edge79+
Edge (Legacy)12+Internet Explorer10+
Firefox Android?Safari iOS5+Chrome Android?WebView Android37+Samsung Internet?Opera Android12.1+

The control is suffering from an underflow.

rangeOverflow

ValidityState/rangeOverflow

Support in all current engines.

Firefox4+Safari5+Chrome4+
Opera12.1+Edge79+
Edge (Legacy)12+Internet Explorer10+
Firefox Android?Safari iOS5+Chrome Android?WebView Android37+Samsung Internet?Opera Android12.1+

The control is suffering from an overflow.

stepMismatch

ValidityState/stepMismatch

Support in all current engines.

Firefox4+Safari5+Chrome4+
Opera12.1+Edge79+
Edge (Legacy)12+Internet Explorer10+
Firefox Android?Safari iOS5+Chrome Android?WebView Android37+Samsung Internet?Opera Android12.1+

The control is suffering from a step mismatch.

badInput

The control is suffering from bad input.

customError

The control is suffering from a custom error.

valid

None of the other conditions are true.

The check validity steps for an element element are:

  1. If element is a candidate for constraint validation and does not satisfy its constraints, then:

    1. Fire an event named invalid at element, with the cancelable attribute initialized to true (though canceling has no effect).

    2. falseを返す。

  2. Return true.

The checkValidity() method, when invoked, must run the check validity steps on this element.

ElementInternals/checkValidity

Support in all current engines.

Firefox98+Safari16.4+Chrome77+
Opera?Edge79+
Edge (Legacy)?Internet ExplorerNo
Firefox Android?Safari iOS?Chrome Android?WebView Android?Samsung Internet?Opera Android?

The checkValidity() method of the ElementInternals interface must run these steps:

  1. Let element be this ElementInternals's target element.

  2. If element is not a form-associated custom element, then throw a "NotSupportedError" DOMException.

  3. Run the check validity steps on element.

The report validity steps for an element element are:

  1. If element is a candidate for constraint validation and does not satisfy its constraints, then:

    1. Let report be the result of firing an event named invalid at element, with the cancelable attribute initialized to true.

    2. If report is true, then report the problems with the constraints of this element to the user. When reporting the problem with the constraints to the user, the user agent may run the focusing steps for element, and may change the scrolling position of the document, or perform some other action that brings element to the user's attention. User agents may report more than one constraint violation, if element suffers from multiple problems at once. If element is not being rendered, then the user agent may, instead of notifying the user, report the error for the running script.

    3. falseを返す。

  2. Return true.

The reportValidity() method, when invoked, must run the report validity steps on this element.

ElementInternals/reportValidity

Support in all current engines.

Firefox98+Safari16.4+Chrome77+
Opera?Edge79+
Edge (Legacy)?Internet ExplorerNo
Firefox Android?Safari iOS?Chrome Android?WebView Android?Samsung Internet?Opera Android?

The reportValidity() method of the ElementInternals interface must run these steps:

  1. Let element be this ElementInternals's target element.

  2. If element is not a form-associated custom element, then throw a "NotSupportedError" DOMException.

  3. Run the report validity steps on element.

The validationMessage attribute's getter must run these steps:

  1. If this element is not a candidate for constraint validation or if this element satisfies its constraints, then return the empty string.

  2. Return a suitably localized message that the user agent would show the user if this were the only form control with a validity constraint problem. If the user agent would not actually show a textual message in such a situation (e.g., it would show a graphical cue instead), then return a suitably localized message that expresses (one or more of) the validity constraint(s) that the control does not satisfy. If the element is a candidate for constraint validation and is suffering from a custom error, then the custom validity error message should be present in the return value.

4.10.20.4 セキュリティ

サーバーは、クライアント側の検証に依存すべきではない。クライアント側の検証は、悪意あるユーザーによって意図的にバイパスされ、古いユーザーエージェントまたは、これらの機能を実装しない自動化ツールのユーザーによって意図せずに回避されうる。制約検証機能は、あらゆる種類のセキュリティメカニズムを提供することでなく、ユーザーの利便性を向上させることのみを意図する。

4.10.21 フォームの送信

4.10.21.1 導入

この節は非規範的である。

フォームが送信されるとき、フォーム内のデータはenctypeで指定した構造体に変換され、指定したメソッドを使用するアクションで指定した宛先に送信される。

たとえば、次のような形式をとる:

<form action="/find.cgi" method=get>
 <input type=text name=t>
 <input type=search name=q>
 <input type=submit>
</form>

ユーザーが最初のフィールドで"cat"および2番目で"猫"と入力し、次に送信ボタンを押す場合、ユーザーエージェントは/find.cgi?t=cats&q=furを読み込む。

一方、このフォームを考えてみる:

<form action="/find.cgi" method=post enctype="multipart/form-data">
 <input type=text name=t>
 <input type=search name=q>
 <input type=submit>
</form>

同じユーザー入力を考えると、提出上の結果はかなり異なる:ユーザーエージェントは、次のテキストのようなエンティティボディとして、代わりに指定されたURLにHTTP POSTを行う。

------kYFrd4jNJEgCervE
Content-Disposition: form-data; name="t"

cats
------kYFrd4jNJEgCervE
Content-Disposition: form-data; name="q"

fur
------kYFrd4jNJEgCervE--
4.10.21.2 Implicit submission

A form element's default button is the first submit button in tree order whose form owner is that form element.

If the user agent supports letting the user submit a form implicitly (for example, on some platforms hitting the "enter" key while a text control is focused implicitly submits the form), then doing so for a form, whose default button has activation behavior and is not disabled, must cause the user agent to fire a click event at that default button.

There are pages on the web that are only usable if there is a way to implicitly submit forms, so user agents are strongly encouraged to support this.

If the form has no submit button, then the implicit submission mechanism must perform the following steps:

  1. If the form has more than one field that blocks implicit submission, then return.

  2. Submit the form element from the form element itself with userInvolvement set to "activation".

For the purpose of the previous paragraph, an element is a field that blocks implicit submission of a form element if it is an input element whose form owner is that form element and whose type attribute is in one of the following states: Text, Search, Telephone, URL, Email, Password, Date, Month, Week, Time, Local Date and Time, Number

4.10.21.3 Form submission algorithm

Each form element has a constructing entry list boolean, initially false.

Each form element has a firing submission events boolean, initially false.

To submit a form element form from an element submitter (typically a button), given an optional boolean submitted from submit() method (default false) and an optional user navigation involvement userInvolvement (default "none"):

  1. If form cannot navigate, then return.

  2. If form's constructing entry list is true, then return.

  3. Let form document be form's node document.

  4. If form document's active sandboxing flag set has its sandboxed forms browsing context flag set, then return.

  5. If submitted from submit() method is false, then:

    1. If form's firing submission events is true, then return.

    2. Set form's firing submission events to true.

    3. For each element field in the list of submittable elements whose form owner is form, set field's user validity to true.

    4. If the submitter element's no-validate state is false, then interactively validate the constraints of form and examine the result. If the result is negative (i.e., the constraint validation concluded that there were invalid fields and probably informed the user of this), then:

      1. Set form's firing submission events to false.

      2. Return.

    5. Let submitterButton be null if submitter is form. Otherwise, let submitterButton be submitter.

    6. Let shouldContinue be the result of firing an event named submit at form using SubmitEvent, with the submitter attribute initialized to submitterButton, the bubbles attribute initialized to true, and the cancelable attribute initialized to true.

    7. Set form's firing submission events to false.

    8. If shouldContinue is false, then return.

    9. If form cannot navigate, then return.

      Cannot navigate is run again as dispatching the submit event could have changed the outcome.

  6. Let encoding be the result of picking an encoding for the form.

  7. Let entry list be the result of constructing the entry list with form, submitter, and encoding.

  8. Assert: entry list is not null.

  9. If form cannot navigate, then return.

    Cannot navigate is run again as dispatching the formdata event in constructing the entry list could have changed the outcome.

  10. Let method be the submitter element's method.

  11. If method is dialog, then:

    1. If form does not have an ancestor dialog element, then return.

    2. Let subject be form's nearest ancestor dialog element.

    3. Let result be null.

    4. If submitter is an input element whose type attribute is in the Image Button state, then:

      1. Let (x, y) be the selected coordinate.

      2. Set result to the concatenation of x, ",", and y.

    5. Otherwise, if submitter has a value, then set result to that value.

    6. Close the dialog subject with result.

    7. Return.

  12. Let action be the submitter element's action.

  13. If action is the empty string, let action be the URL of the form document.

  14. Let parsed action be the result of encoding-parsing a URL given action, relative to submitter's node document.

  15. If parsed action is failure, then return.

  16. Let scheme be the scheme of parsed action.

  17. Let enctype be the submitter element's enctype.

  18. Let formTarget be null.

  19. If the submitter element is a submit button and it has a formtarget attribute, then set formTarget to the formtarget attribute value.

  20. Let target be the result of getting an element's target given submitter's form owner and formTarget.

  21. Let noopener be the result of getting an element's noopener with form and target.

  22. Let targetNavigable be the first return value of applying the rules for choosing a navigable given target, form's node navigable, and noopener.

  23. If targetNavigable is null, then return.

  24. Let historyHandling be "auto".

  25. If form document equals targetNavigable's active document, and form document has not yet completely loaded, then set historyHandling to "replace".

  26. Select the appropriate row in the table below based on scheme as given by the first cell of each row. Then, select the appropriate cell on that row based on method as given in the first cell of each column. Then, jump to the steps named in that cell and defined below the table.

    GETPOST
    httpMutate action URLSubmit as entity body
    httpsMutate action URLSubmit as entity body
    ftpGet action URLGet action URL
    javascriptGet action URLGet action URL
    dataMutate action URLGet action URL
    mailtoMail with headersMail as body

    If scheme is not one of those listed in this table, then the behavior is not defined by this specification. User agents should, in the absence of another specification defining this, act in a manner analogous to that defined in this specification for similar schemes.

    Each form element has a planned navigation, which is either null or a task; when the form is first created, its planned navigation must be set to null. In the behaviors described below, when the user agent is required to plan to navigate to a URL url given an optional POST resource-or-null postResource (default null), it must run the following steps:

    1. Let referrerPolicy be the empty string.

    2. If the form element's link types include the noreferrer keyword, then set referrerPolicy to "no-referrer".

    3. If the form has a non-null planned navigation, remove it from its task queue.

    4. Queue an element task on the DOM manipulation task source given the form element and the following steps:

      1. Set the form's planned navigation to null.

      2. Navigate targetNavigable to url using the form element's node document, with historyHandling set to historyHandling, userInvolvement set to userInvolvement, referrerPolicy set to referrerPolicy, documentResource set to postResource, and formDataEntryList set to entry list.

    5. Set the form's planned navigation to the just-queued task.

    The behaviors are as follows:

    Mutate action URL

    Let pairs be the result of converting to a list of name-value pairs with entry list.

    Let query be the result of running the application/x-www-form-urlencoded serializer with pairs and encoding.

    Set parsed action's query component to query.

    Plan to navigate to parsed action.

    Submit as entity body

    Assert: method is POST.

    Switch on enctype:

    application/x-www-form-urlencoded

    Let pairs be the result of converting to a list of name-value pairs with entry list.

    Let body be the result of running the application/x-www-form-urlencoded serializer with pairs and encoding.

    Set body to the result of encoding body.

    Let mimeType be `application/x-www-form-urlencoded`.

    multipart/form-data

    Let body be the result of running the multipart/form-data encoding algorithm with entry list and encoding.

    Let mimeType be the isomorphic encoding of the concatenation of "multipart/form-data; boundary=" and the multipart/form-data boundary string generated by the multipart/form-data encoding algorithm.

    text/plain

    Let pairs be the result of converting to a list of name-value pairs with entry list.

    Let body be the result of running the text/plain encoding algorithm with pairs.

    Set body to the result of encoding body using encoding.

    Let mimeType be `text/plain`.

    Plan to navigate to parsed action given a POST resource whose request body is body and request content-type is mimeType.

    Get action URL

    Plan to navigate to parsed action.

    entry list is discarded.

    Mail with headers

    Let pairs be the result of converting to a list of name-value pairs with entry list.

    Let headers be the result of running the application/x-www-form-urlencoded serializer with pairs and encoding.

    Replace occurrences of U+002B PLUS SIGN characters (+) in headers with the string "%20".

    Set parsed action's query to headers.

    Plan to navigate to parsed action.

    Mail as body

    Let pairs be the result of converting to a list of name-value pairs with entry list.

    Switch on enctype:

    text/plain

    Let body be the result of running the text/plain encoding algorithm with pairs.

    Set body to the result of running UTF-8 percent-encode on body using the default encode set. [URL]

    そうでなければ

    Let body be the result of running the application/x-www-form-urlencoded serializer with pairs and encoding.

    If parsed action's query is null, then set it to the empty string.

    If parsed action's query is not the empty string, then append a single U+0026 AMPERSAND character (&) to it.

    Append "body=" to parsed action's query.

    Append body to parsed action's query.

    Plan to navigate to parsed action.

4.10.21.4 Constructing the entry list

An entry list is a list of entries, typically representing the contents of a form. An entry is a tuple consisting of a name (a scalar value string) and a value (either a scalar value string or a File object).

To create an entry given a string name, a string or Blob object value, and optionally a scalar value string filename:

  1. Set name to the result of converting name into a scalar value string.

  2. If value is a string, then set value to the result of converting value into a scalar value string.

  3. Otherwise:

    1. If value is not a File object, then set value to a new File object, representing the same bytes, whose name attribute value is "blob".

    2. If filename is given, then set value to a new File object, representing the same bytes, whose name attribute is filename.

    These operations will create a new File object if either filename is given or the passed Blob is not a File object. In those cases, the identity of the passed Blob object is not kept.

  4. Return an entry whose name is name and whose value is value.

To construct the entry list given a form, an optional submitter (default null), and an optional encoding (default UTF-8):

  1. If form's constructing entry list is true, then return null.

  2. Set form's constructing entry list to true.

  3. Let controls be a list of all the submittable elements whose form owner is form, in tree order.

  4. Let entry list be a new empty entry list.

  5. For each element field in controls, in tree order:

    1. If any of the following are true:

      then continue.

    2. If the field element is an input element whose type attribute is in the Image Button state, then:

      1. If the field element is not submitter, then continue.

      2. If the field element has a name attribute specified and its value is not the empty string, let name be that value followed by U+002E (.). Otherwise, let name be the empty string.

      3. Let namex be the concatenation of name and U+0078 (x).

      4. Let namey be the concatenation of name and U+0079 (y).

      5. Let (x, y) be the selected coordinate.

      6. Create an entry with namex and x, and append it to entry list.

      7. Create an entry with namey and y, and append it to entry list.

      8. Continue.

    3. If the field is a form-associated custom element, then perform the entry construction algorithm given field and entry list, then continue.

    4. If either the field element does not have a name attribute specified, or its name attribute's value is the empty string, then continue.

    5. Let name be the value of the field element's name attribute.

    6. If the field element is a select element, then for each option element in the select element's list of options whose selectedness is true and that is not disabled, create an entry with name and the value of the option element, and append it to entry list.

    7. Otherwise, if the field element is an input element whose type attribute is in the Checkbox state or the Radio Button state, then:

      1. If the field element has a value attribute specified, then let value be the value of that attribute; otherwise, let value be the string "on".

      2. Create an entry with name and value, and append it to entry list.

    8. Otherwise, if the field element is an input element whose type attribute is in the File Upload state, then:

      1. If there are no selected files, then create an entry with name and a new File object with an empty name, application/octet-stream as type, and an empty body, and append it to entry list.

      2. Otherwise, for each file in selected files, create an entry with name and a File object representing the file, and append it to entry list.

    9. Otherwise, if the field element is an input element whose type attribute is in the Hidden state and name is an ASCII case-insensitive match for "_charset_":

      1. Let charset be the name of encoding.

      2. Create an entry with name and charset, and append it to entry list.

    10. Otherwise, create an entry with name and the value of the field element, and append it to entry list.

    11. If the element has a dirname attribute, that attribute's value is not the empty string, and the element is an auto-directionality form-associated element:

      1. Let dirname be the value of the element's dirname attribute.

      2. Let dir be the string "ltr" if the directionality of the element is 'ltr', and "rtl" otherwise (i.e., when the directionality of the element is 'rtl').

      3. Create an entry with dirname and dir, and append it to entry list.

  6. Let form data be a new FormData object associated with entry list.

  7. Fire an event named formdata at form using FormDataEvent, with the formData attribute initialized to form data and the bubbles attribute initialized to true.

  8. Set form's constructing entry list to false.

  9. Return a clone of entry list.

4.10.21.5 Selecting a form submission encoding

If the user agent is to pick an encoding for a form, it must run the following steps:

  1. Let encoding be the document's character encoding.

  2. If the form element has an accept-charset attribute, set encoding to the return value of running these substeps:

    1. Let input be the value of the form element's accept-charset attribute.

    2. Let candidate encoding labels be the result of splitting input on ASCII whitespace.

    3. Let candidate encodings be an empty list of character encodings.

    4. For each token in candidate encoding labels in turn (in the order in which they were found in input), get an encoding for the token and, if this does not result in failure, append the encoding to candidate encodings.

    5. If candidate encodings is empty, return UTF-8.

    6. Return the first encoding in candidate encodings.

  3. Return the result of getting an output encoding from encoding.

4.10.21.6 Converting an entry list to a list of name-value pairs

The application/x-www-form-urlencoded and text/plain encoding algorithms take a list of name-value pairs, where the values must be strings, rather than an entry list where the value can be a File. The following algorithm performs the conversion.

To convert to a list of name-value pairs an entry list entry list, run these steps:

  1. Let list be an empty list of name-value pairs.

  2. For each entry of entry list:

    1. Let name be entry's name, with every occurrence of U+000D (CR) not followed by U+000A (LF), and every occurrence of U+000A (LF) not preceded by U+000D (CR), replaced by a string consisting of U+000D (CR) and U+000A (LF).

    2. If entry's value is a File object, then let value be entry's value's name. Otherwise, let value be entry's value.

    3. Replace every occurrence of U+000D (CR) not followed by U+000A (LF), and every occurrence of U+000A (LF) not preceded by U+000D (CR), in value, by a string consisting of U+000D (CR) and U+000A (LF).

    4. Append to list a new name-value pair whose name is name and whose value is value.

  3. listを返す。

4.10.21.7 URL-encoded form data

application/x-www-form-urlencodedの詳細については、URLを参照のこと。[URL]

4.10.21.8 Multipart form data

The multipart/form-data encoding algorithm, given an entry list entry list and an encoding encoding, is as follows:

  1. For each entry of entry list:

    1. Replace every occurrence of U+000D (CR) not followed by U+000A (LF), and every occurrence of U+000A (LF) not preceded by U+000D (CR), in entry's name, by a string consisting of a U+000D (CR) and U+000A (LF).

    2. If entry's value is not a File object, then replace every occurrence of U+000D (CR) not followed by U+000A (LF), and every occurrence of U+000A (LF) not preceded by U+000D (CR), in entry's value, by a string consisting of a U+000D (CR) and U+000A (LF).

  2. Return the byte sequence resulting from encoding the entry list using the rules described by RFC 7578, Returning Values from Forms: multipart/form-data, given the following conditions: [RFC7578]

multipart/form-dataのペイロードを解釈する方法の詳細については、RFC 7578を参照のこと。[RFC7578]

4.10.21.9 Plain text form data

The text/plain encoding algorithm, given a list of name-value pairs pairs, is as follows:

  1. Let result be the empty string.

  2. For each pair in pairs:

    1. Append pair's name to result.

    2. Append a single U+003D EQUALS SIGN character (=) to result.

    3. Append pair's value to result.

    4. Append a U+000D CARRIAGE RETURN (CR) U+000A LINE FEED (LF) character pair to result.

  3. Return result.

text/plainフォーマットを使用するペイロードは、人間可読であることを意図される。形式は不明瞭である(たとえば、値の末尾の改行と値でのリテラルの改行を区別する方法はない)ので、これらはコンピューターによって確実に解釈されない。

4.10.21.10 SubmitEventインターフェイス

SubmitEvent

Support in all current engines.

Firefox75+Safari15+Chrome81+
Opera?Edge81+
Edge (Legacy)?Internet ExplorerNo
Firefox Android?Safari iOS?Chrome Android?WebView Android?Samsung Internet?Opera Android?

SubmitEvent/SubmitEvent

Support in all current engines.

Firefox75+Safari15+Chrome81+
Opera?Edge81+
Edge (Legacy)?Internet ExplorerNo
Firefox Android?Safari iOS?Chrome Android?WebView Android?Samsung Internet?Opera Android?
[Exposed=Window]
interface SubmitEvent : Event {
  constructor(DOMString type, optional SubmitEventInit eventInitDict = {});

  readonly attribute HTMLElement? submitter;
};

dictionary SubmitEventInit : EventInit {
  HTMLElement? submitter = null;
};
event.submitter

フォームの送信をトリガーした送信ボタンを表す要素を返す。または、送信によってトリガーされなかった場合はnullを返す。

The submitter attribute must return the value it was initialized to.

4.10.21.11 FormDataEventインターフェイス

FormDataEvent/FormDataEvent

Support in all current engines.

Firefox72+Safari15+Chrome77+
Opera?Edge79+
Edge (Legacy)?Internet ExplorerNo
Firefox Android?Safari iOS?Chrome Android?WebView Android?Samsung Internet?Opera Android?

FormDataEvent

Support in all current engines.

Firefox72+Safari15+Chrome77+
Opera?Edge79+
Edge (Legacy)?Internet ExplorerNo
Firefox Android?Safari iOS?Chrome Android?WebView Android?Samsung Internet?Opera Android?
[Exposed=Window]
interface FormDataEvent : Event {
  constructor(DOMString type, FormDataEventInit eventInitDict);

  readonly attribute FormData formData;
};

dictionary FormDataEventInit : EventInit {
  required FormData formData;
};
event.formData

ターゲットのform.に関連付けられている要素の名前と値を表すFormDataオブジェクトを返す。FormDataオブジェクトに対する操作は、送信されるフォームデータに影響する。

The formData attribute must return the value it was initialized to. It represents a FormData object associated to the entry list that is constructed when the form is submitted.

4.10.22 Resetting a form

When a form element form is reset, run these steps:

  1. Let reset be the result of firing an event named reset at form, with the bubbles and cancelable attributes initialized to true.

  2. If reset is true, then invoke the reset algorithm of each resettable element whose form owner is form.

Each resettable element defines its own reset algorithm. Changes made to form controls as part of these algorithms do not count as changes caused by the user (and thus, e.g., do not cause input events to fire).