Living Standard — Last Updated 12 December 2024
name
attributedirname
attributemaxlength
attributeminlength
attributedisabled
attributeSubmitEvent
interfaceFormDataEvent
interface多くのフォームコントロールは、値とcheckednessを持つ。(後者は、input
要素によってのみ使用される。)これらは、ユーザーがコントロールと対話する方法を記述するために使用される。
コントロールの値はそのコントロールの初期状態である。それ自体は、ユーザーの現在の入力と一致しないかもしれない。
たとえば、ユーザーが数字を期待する数値フィールドに単語"three"を入力する場合、ユーザーの入力は文字列"three"であるがコントロールの値は変わらないままとなる。また、ユーザーがeメールフィールドに(先頭の空白文字とともに)電子メールアドレス" awesome@example.com"を入力する場合、ユーザーの入力は文字列" awesome@example.com"であるが、eメールフィールドに対するブラウザーのUIは(先頭の空白文字なしで)"awesome@example.com
"の値に直すかもしれない。
input
and textarea
elements have a dirty value flag. This is used to track the interaction between the value and default value. If it is false, value mirrors the default 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が代わりに使用されるものである。
フォームコントロールはmutableとして指定することができる。
これは、ユーザーがフォームコントロールの値またはcheckednessを変更できるかどうか、またはコントロールを自動的に事前入力できるかどうかを(要素が指定されようとなかろうと依存する本仕様での定義及び要件によって)判定する。
フォーム関連要素は、要素のフォーム所有者と呼ばれるform
要素との関係を持つことができる。フォーム関連要素がform
要素に関連付けられない場合、そのフォーム所有者はnullであると言われる。
フォーム関連要素は、関連するパーサー挿入フラグを持つ。
Support in all current engines.
Support in all current engines.
デフォルトで、フォーム関連要素が(下記のように)その最も近い祖先form
要素に関連付けらるが、listedである場合、これを上書きするためにform
属性を指定されてもよい。
この機能は、著者がネストされたform
要素に対するサポートの不足を回避することができる。
listedフォーム関連要素が指定された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:
Unset element's parser inserted flag.
If all of the following are true:
element's form owner is not null;
element is not listed or its form
content attribute is not present; and
element's form owner is its nearest form
element ancestor after the change to the ancestor chain,
then return.
Set element's form owner to null.
If element is listed, has a form
content attribute, and is connected, then:
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.
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
Support in all current engines.
Support in all current engines.
要素のフォーム所有者を返す。
存在しない場合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.
Support in all current engines.
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.
name
attributeSupport in all current engines.
name
コンテンツ属性は、フォームの送信やform
要素のelements
オブジェクトで使用されるような、フォームコントロールの名前を与える。属性が指定される場合、その値は空の文字列またはでisindex
あってはならない。
多くのユーザーエージェントは歴史的に、名前isindex
をもつフォームの最初のテキストコントロールを特別にサポートしており、この仕様は以前に関連するユーザーエージェント要件が定義されていた。しかし、一部のユーザーエージェントは、その後、その特別なサポートを削除し、関連する要件はこの仕様から削除された。よって、レガシーユーザーエージェントで問題のある再解釈を避けるために、isindex
という名前はもはや許可されない。
isindex
以外で、name
に対して任意の空でない値が許可される。An ASCII case-insensitive match for the name _charset_
is special: if used as the name of a control with no value
attribute, then during submission the value
attribute is automatically given a value consisting of the submission character encoding.
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
要素を指す。
dirname
attributeSupport in all current engines.
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
maxlength
attributeダーティ値フラグによって制御される、フォームコントロールmaxlength
属性は、ユーザーが入力できる文字数の制限を宣言する。The number of characters is measured using length and, in the case of textarea
elements, with all newlines normalized to a single character (as opposed to CRLF pairs).
要素がフォームコントロール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).
minlength
attributeダーティ値フラグによって制御されるフォームコントロールminlength
属性は、ユーザーが入力できる文字数の下限を宣言する。The "number of characters" is measured using length and, in the case of textarea
elements, with all newlines normalized to a single character (as opposed to CRLF pairs).
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 >
disabled
attributeSupport in all current engines.
Support in all current engines.
Support in all current engines.
Support in all current engines.
Support in all current engines.
disabled
コンテンツ属性は、真偽属性である。
option
要素に対するdisabled
属性およびoptgroup
要素に対するdisabled
属性は、別々に定義されている。
A form control is disabled if any of the following are true:
the element is a button
, input
, select
, textarea
, or form-associated custom element, and the disabled
attribute is specified on this element (regardless of its value); or
the element is a descendant of a fieldset
element whose disabled
attribute is specified, and is not a descendant of that fieldset
element's first legend
element child, if any.
無効であるフォームコントロールは、要素に送出されていることからユーザーインタラクションタスクソース上のキューに入れられる任意のclick
イベントを防がなければならない。
Constraint validation: If an element is disabled, it is barred from constraint validation.
Support in all current engines.
Support in all current engines.
disabled
IDL属性は、disabled
コンテンツ属性を反映しなければならない。
Element/form#Attributes_for_form_submission
Support in all current engines.
フォーム送信のための属性は、form
要素上と送信ボタン上(フォーム送信ボタンを表す要素、たとえば、type
属性のinput
要素がSubmit Button状態にある)の両方を指定できる。
form
要素で指定されてもよいフォーム送信のための属性は、action
、enctype
、method
、novalidate
、target
である。
送信ボタンで指定されてもよい対応するフォーム送信のための属性は、formaction
、formenctype
、formmethod
、formnovalidate
、formtarget
である。省略した場合、これらはform
要素の対応する属性で指定された値をデフォルトとする。
Support in all current engines.
指定される場合、action
およびformaction
コンテンツ属性は、潜在的にスペースで囲まれた妥当な空でないURLである値を持たなければならない。
要素が送信ボタンでありかつそのような属性を持つ場合、要素のactionはその要素のformaction
属性値である。すなわちactionがそのような属性を持つ場合、そのフォーム所有者のaction
属性値であり、そうでなければ空文字列である。
Support in all current engines.
method
およびformmethod
コンテンツ属性以下のキーワードおよび状態をもつ列挙属性である:
キーワード | 状態 | 概要 |
---|---|---|
get | GET | Indicates the form will use the HTTP GET method. |
post | POST | Indicates the form will use the HTTP POST method. |
dialog | Dialog | Indicates 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 >
この例において、form
はdialog
とともに使用される。フォームの送信時に、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 >
Support in all current engines.
enctype
およびformenctype
コンテンツ属性は、次のキーワードおよび状態をもつ列挙属性である:
application/x-www-form-urlencoded
"キーワードおよび対応する状態。multipart/form-data
"キーワードおよび対応する状態。text/plain
"キーワードおよび対応する状態。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
属性状態である。
Support in all current engines.
The target
and formtarget
content attributes, if specified, must have values that are valid navigable target names or keywords.
Support in all current engines.
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 >
Support in all current engines.
Support in all current engines.
Support in all current engines.
Support in all current engines.
Support in all current engines.
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.
autocomplete
attributeSupport in all current engines.
ユーザーエージェントは、たとえば以前のユーザー入力に基づくユーザーのアドレスを事前に入力するなど、ユーザーにフォームの記入を助けるための機能を持つこともある。autocomplete
コンテンツ属性は、ユーザーエージェントへのヒントの手段に、または実際にそのような機能を提供するかどうかに使用できる。
この属性が使用される2つの状態が存在する。オートフィル予想マントの着用時、autocomplete
属性は、入力がユーザーから予想されるものについて説明する。オートフィルアンカーマントの着用時、autocomplete
属性は、指定された値の意味を説明する。
type
属性が 状態にあるinput
要素では、autocomplete
属性は、オートフィルアンカーマントを着用する。他のすべての場合で、オートフィル予想マントを着用する。
オートフィル予想マントを着用時、autocomplete
属性が指定される場合、文字列"off
"とマッチするASCII大文字・小文字不区別である単一のトークン、または文字列"on
"とマッチするASCII大文字・小文字不区別である単一のトークン、またはオートフィル詳細トークンののいずれかから成る順序付きスペースで区切りトークンの集合である値を持たなければならない。
オートフィルアンカーマントを着用時、autocomplete
属性が指定される場合、ちょうどオートフィル詳細トークンから成る順序付きスペースで区切りトークンの集合の値を持たなければならない(すなわち、"on
"と"off
"キーワードが許可されない)。
オートフィルの詳細トークンは下記の順序で、次のとおり:
任意で、フィールドが名前グループに属することを意味する、最初の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 >
任意で、以下の文字列のいずれかとASCII大文字・小文字不区別で一致するトークン:
shipping
"billing
"次の2つのオプションについていずれか:
コントロールにふさわしくないものを除いて、以下のオートフィルフィールド名のいずれかとASCII大文字・小文字不区別で一致するトークン:
name
"honorific-prefix
"given-name
"additional-name
"family-name
"honorific-suffix
"nickname
"username
"new-password
"current-password
"one-time-code
"organization-title
"organization
"street-address
"address-line1
"address-line2
"address-line3
"address-level4
"address-level3
"address-level2
"address-level1
"country
"country-name
"postal-code
"cc-name
"cc-given-name
"cc-additional-name
"cc-family-name
"cc-number
"cc-exp
"cc-exp-month
"cc-exp-year
"cc-csc
"cc-type
"transaction-currency
"transaction-amount
"language
"bday
"bday-day
"bday-month
"bday-year
"sex
"url
"photo
"(これらの値の説明については、以下の表を参照のこと。)
以下の与えられた順序で:
任意で、以下の文字列のいずれかとASCII大文字・小文字不区別で一致するトークン:
home
"work
"mobile
"fax
"pager
"コントロールにふさわしくないものを除いて、以下のオートフィルフィールド名のいずれかとASCII大文字・小文字不区別で一致するトークン:
tel
"tel-country-code
"tel-national
"tel-area-code
"tel-local
"tel-local-prefix
"tel-local-suffix
"tel-extension
"email
"impp
"(これらの値の説明については、以下の表を参照のこと。)
Optionally, a token that is an ASCII case-insensitive match for the string "webauthn
", meaning the user agent should show public key credentials available via conditional
mediation when the user interacts with the form control. webauthn
is only valid for input
and textarea
elements.
先に述べたように、属性およびそのキーワードの意味は属性が着用するマントに依存する。
"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番目に、および他の多くは、単に一つの名前を(mononym)を持つ。したがって、単一のフィールドを持つことは、より柔軟性がある。
一部のフィールドは、特定のフォームコントロールに適している。コントロールが、次の表でオートフィルフィールドを記述した最初の行の5列目でオートフィルフィールドにリストされたグループに属していない場合、オートフィルフィールド名は、コントロールに不適切である。 どのようなコントロールが各グループに分類されるかは、下記の表に記載される。
フィールド名 | 意味 | 標準的なフォーマット | 標準的なフォーマット例 | コントロールグループ | |||
---|---|---|---|---|---|---|---|
"name " | フルネーム | 自由形式テキスト、改行なし | Sir Timothy John Berners-Lee, OM, KBE, FRS, FREng, FRSA | Text | |||
"honorific-prefix " | 敬称または爵位(たとえば、"Mr."、"Ms."、"Dr."、"Mlle") | 自由形式テキスト、改行なし | Sir | Text | |||
"given-name " | Given name(一部の西洋文化において、first nameとして知られる) | 自由形式テキスト、改行なし | Timothy | Text | |||
"additional-name " | Additional names(一部の西洋文化において、middle namesとして知られる) | 自由形式テキスト、改行なし | John | Text | |||
"family-name " | Family name(一部の西洋文化において、last nameまたはsurnameとして知られる) | 自由形式テキスト、改行なし | Berners-Lee | Text | |||
"honorific-suffix " | 接頭辞(たとえば、"Jr."、"B.Sc."、"MBASW"、"II") | 自由形式テキスト、改行なし | OM, KBE, FRS, FREng, FRSA | Text | |||
"nickname " | ニックネーム、スクリーンネーム、ハンドル:フルネームの代わりに使用する一般的に短い名前 | 自由形式テキスト、改行なし | Tim | Text | |||
"organization-title " | 職種(たとえば"Software Engineer"、"Senior Vice President"、"Deputy Managing Director") | 自由形式テキスト、改行なし | Professor | Text | |||
"username " | ユーザー名 | 自由形式テキスト、改行なし | timbl | Username | |||
"new-password " | 新しいパスワード(たとえば、アカウントの作成またはパスワードの変更の場合) | 自由形式テキスト、改行なし | GUMFXbadyrS3 | Password | |||
"current-password " | username フィールドによって識別されるアカウントに対する現在のパスワード(たとえば、ログイン時) | 自由形式テキスト、改行なし | qwerty | Password | |||
"one-time-code " | One-time code used for verifying user identity | 自由形式テキスト、改行なし | 123456 | Password | |||
"organization " | 人、アドレス、またはこのフィールドに関連付けられた他のフィールドの連絡先情報に対応する会社名 | 自由形式テキスト、改行なし | World Wide Web Consortium | Text | |||
"street-address " | 所在地住所(複数行、改行を保持) | 自由形式テキスト | 32 Vassar Street MIT Room 32-G524 | Multiline | |||
"address-line1 " | 所在地住所(フィールドごとに1行) | 自由形式テキスト、改行なし | 32 Vassar Street | Text | |||
"address-line2 " | 自由形式テキスト、改行なし | MIT Room 32-G524 | Text | ||||
"address-line3 " | 自由形式テキスト、改行なし | Text | |||||
"address-level4 " | 4つの行政レベルでのアドレスの中で、最もきめ細かい行政レベル。 | 自由形式テキスト、改行なし | Text | ||||
"address-level3 " | 3つ以上の行政レベルの住所で、第3行政レベル | 自由形式テキスト、改行なし | Text | ||||
"address-level2 " | 2つ以上の管理レベルの住所で、第2管理レベル。2つの行政レベルをもつ国で、これは通常、関連する所在地住所が見つけられる、市、町、村、または他の地方になる | 自由形式テキスト、改行なし | Cambridge | Text | |||
"address-level1 " | 住所で最も広範な行政レベル、すなわち位置関係が発見される中の地方。たとえば、アメリカで、これは州(state)になる。スイスで州(canton)になる。英国で、郵便町(post town)になる。 | 自由形式テキスト、改行なし | MA | Text | |||
"country " | 国コード | 妥当なISO 3166-1-alpha-2国コード [ISO3166] | US | Text | |||
"country-name " | 国名 | 自由形式テキスト、改行なし。一部の場合でcountry 由来 | US | Text | |||
"postal-code " | 郵便番号、ZIPコード、CEDEXコード(CEDEXの場合、"CEDEX"を、関連する場合郡を、address-level2 フィールドに追加する) | 自由形式テキスト、改行なし | 02139 | Text | |||
"cc-name " | 決済手段に与えられるようなフルネーム | 自由形式テキスト、改行なし | Tim Berners-Lee | Text | |||
"cc-given-name " | 決済手段に与えられるようなGiven name (一部の西洋文化において、first nameとして知られる) | 自由形式テキスト、改行なし | Tim | Text | |||
"cc-additional-name " | 決済手段に与えられるようなAdditional names(一部の西洋文化において、middle namesとして知られる) | 自由形式テキスト、改行なし | Text | ||||
"cc-family-name " | 決済手段に与えられるようなFamily name (一部の西洋文化において、last nameまたはsurnameとして知られる) | 自由形式テキスト、改行なし | Berners-Lee | Text | |||
"cc-number " | 決済手段(たとえばクレジットカード番号)を識別するコード | ASCII digits | 4114360123456785 | Text | |||
"cc-exp " | 決済手段の有効期限 | Valid month string | 2014-12 | Month | |||
"cc-exp-month " | 決済手段の有効期限の月コンポーネント | 1から12までの範囲で妥当な整数 | 12 | Numeric | |||
"cc-exp-year " | 決済手段の有効期限の年コンポーネント | 0より大きい妥当な整数 | 2014 | Numeric | |||
"cc-csc " | Security code for the payment instrument (also known as the card security code (CSC), card validation code (CVC), card verification value (CVV), signature panel code (SPC), credit card ID (CCID), etc.) | ASCII digits | 419 | Text | |||
"cc-type " | 決済手段の種類 | 自由形式テキスト、改行なし | Visa | Text | |||
"transaction-currency " | ユーザーが使用よりトランザクションを好む通貨 | ISO 4217通貨コード[ISO4217] | GBP | Text | |||
"transaction-amount " | (たとえば、ビッドまたは販売価格を入力する際に)ユーザーがトランザクションに望む金額 | Valid floating-point number | 401.00 | Numeric | |||
"language " | 優先言語 | 妥当なBCP 47言語タグ[BCP47] | ja | Text | |||
"bday " | 誕生日 | Valid date string | 1955-06-08 | Date | |||
"bday-day " | 誕生日の日コンポーネント | 1から31までの範囲で妥当な整数 | 8 | Numeric | |||
"bday-month " | 誕生日の月コンポーネント | 1から12までの範囲で妥当な整数 | 6 | Numeric | |||
"bday-year " | 誕生日の年コンポーネント | 0より大きい妥当な整数 | 1955 | Numeric | |||
"sex " | 性別認識(たとえば、女性、ファファフィネ) | 自由形式テキスト、改行なし | Male | Text | |||
"url " | Home page or other web page corresponding to the company, person, address, or contact information in the other fields associated with this field | Valid URL string | https://www.w3.org/People/Berners-Lee/ | URL | |||
"photo " | 写真、アイコン、会社に対応する他の画像、人、アドレス、またはこのフィールドに関連付けられる他のフィールドの連絡先情報 | Valid URL string | https://www.w3.org/Press/Stock/Berners-Lee/2001-europaeum-eighth.jpg | URL | |||
"tel " | 国コードを含む完全な電話番号 | ASCII数字およびU+0020 SPACE characters、接頭辞としてU+002B PLUS SIGN文字(+) | +1 617 253 5702 | Tel | |||
"tel-country-code " | 電話番号の国コードコンポーネント | ASCII数字、接頭辞としてU+002B PLUS SIGN文字(+) | +1 | Text | |||
"tel-national " | 適用される場合は国の内部の接頭辞とともに、国コードコンポーネントなしの電話番号 | ASCII数字およびU+0020 SPACE characters | 617 253 5702 | Text | |||
"tel-area-code " | 適用される場合は国の内部の接頭辞とともに、電話番号のエリアコードコンポーネント | ASCII digits | 617 | Text | |||
"tel-local " | 国コードと市外局番コンポーネントなしの電話番号 | ASCII digits | 2535702 | Text | |||
"tel-local-prefix " | 2つのコンポーネントに分割される場合、市外局番に続く電話番号のコンポーネントの最初の部分 | ASCII digits | 253 | Text | |||
"tel-local-suffix " | 2つのコンポーネントに分割される場合、市外局番に続く電話番号のコンポーネントの2番目の部分 | ASCII digits | 5702 | Text | |||
"tel-extension " | 電話番号の内部拡張コード | ASCII digits | 1000 | Text | |||
"email " | Email address | Valid email address | timbl@w3.org | Username | |||
"impp " | インスタントメッセージングプロトコルのエンドポイントを表すURL(たとえば、"aim:goim?screenname=example "またはxmpp:fred@example.net ") | Valid URL string | irc://example.org/timbl,isuser | URL |
次のようにグループがコントロールに対応する:
type
属性をもつinput
要素type
属性がText状態であるinput
要素type
属性がSearch状態であるinput
要素textarea
要素select
要素type
属性をもつinput
要素textarea
要素select
要素type
属性をもつinput
要素type
属性がText状態であるinput
要素type
属性がSearch状態であるinput
要素type
属性をもつinput
要素textarea
要素select
要素type
属性をもつinput
要素type
属性がText状態であるinput
要素type
属性がSearch状態であるinput
要素type
属性がURL状態であるinput
要素textarea
要素select
要素type
属性をもつinput
要素type
属性がText状態であるinput
要素type
属性がSearch状態であるinput
要素input
elements with a type
attribute in the Email statetextarea
要素select
要素type
属性をもつinput
要素type
属性がText状態であるinput
要素type
属性がSearch状態であるinput
要素type
属性がTelephone状態であるinput
要素textarea
要素select
要素type
属性をもつinput
要素type
属性がText状態であるinput
要素type
属性がSearch状態であるinput
要素type
属性をもつinput
要素textarea
要素select
要素type
属性をもつinput
要素type
属性がText状態であるinput
要素type
属性がSearch状態であるinput
要素type
属性をもつinput
要素textarea
要素select
要素type
属性をもつinput
要素type
属性がText状態であるinput
要素type
属性がSearch状態であるinput
要素type
属性をもつinput
要素textarea
要素select
要素住所レベル:address-level1
" – "address-level4
"フィールドは、住所の場所を記述するために使用される。異なるロケールは、異なるレベルの数を持つ。たとえば、アメリカは2つのレベル(州および町)を使用し、イギリスは、住所に応じて1つまたは2つ(郵便町、場合によっては地域)を使用しを使用し、中国は3つ(県、市、区)を使用することができる。"address-level1
"フィールドは、最も広い行政区分を表す。異なるロケールは異なる方法でフィールドを順序づける。たとえば、アメリカの町(レベル2)は、州(レベル1)に先行して使用する。一方日本において都道府県(レベル1)は、地区(レベル3)に先行する市(レベル2)に先行する。著者は、(ユーザーが国を変えるのに応じてフィールドを隠す、表示するおよび再配置する)国の慣習と一致する方法で提示された形態を提供することを勧める。
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:
If the element has no autocomplete
attribute, then jump to the step labeled default.
Let tokens be the result of splitting the attribute's value on ASCII whitespace.
If tokens is empty, then jump to the step labeled default.
Let index be the index of the last token in tokens.
Let field be the indexth token in tokens.
Set the category, maximum tokens pair to the result of determining a field's category given field.
If category is null, then jump to the step labeled default.
If the number of tokens in tokens is greater than maximum tokens, then jump to the step labeled default.
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.
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.
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.
Let scope tokens be an empty list.
Let hint tokens be an empty set.
Let credential type be null.
Let IDL value have the same value as field.
If category is Credential and the indexth token in tokens is an ASCII case-insensitive match for "webauthn
", then run the substeps that follow:
Set credential type to "webauthn
".
If the indexth token in tokens is the first entry, then skip to the step labeled done.
Decrement index by one.
Set the category, maximum tokens pair to the result of determining a field's category given the indexth token in tokens.
If category is not Normal and category is not Contact, then jump to the step labeled default.
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.
Set IDL value to the concatenation of the indexth token in tokens, a U+0020 SPACE character, and the previous value of IDL value.
If the indexth token in tokens is the first entry, then skip to the step labeled done.
Decrement index by one.
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:
Let contact be the matching string from the list above.
Insert contact at the start of scope tokens.
Add contact to hint tokens.
Let IDL value be the concatenation of contact, a U+0020 SPACE character, and the previous value of IDL value.
If the indexth entry in tokens is the first entry, then skip to the step labeled done.
Decrement index by one.
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:
Let mode be the matching string from the list above.
Insert mode at the start of scope tokens.
Add mode to hint tokens.
Let IDL value be the concatenation of mode, a U+0020 SPACE character, and the previous value of IDL value.
If the indexth entry in tokens is the first entry, then skip to the step labeled done.
Decrement index by one.
If the indexth entry in tokens is not the first entry, then jump to the step labeled default.
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.
Let section be the indexth token in tokens, converted to ASCII lowercase.
Insert section at the start of scope tokens.
Let IDL value be the concatenation of section, a U+0020 SPACE character, and the previous value of IDL value.
Done: Let the element's autofill hint set be hint tokens.
Let the element's non-autofill credential type be credential type.
Let the element's autofill scope be scope tokens.
Let the element's autofill field name be field.
Let the element's IDL-exposed autofill value be IDL value.
Return.
Default: Let the element's IDL-exposed autofill value be the empty string, and its autofill hint set and autofill scope be empty.
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.
Let form be the element's form owner, if any, or null otherwise.
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:
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).
Otherwise, let maximum tokens and category be the values of the cells in the second and third columns of that row respectively.
Return the pair (category, maximum tokens).
For the purposes of autofill, a control's data depends on the kind of control:
input
element with its type
attribute in the Email state and with the multiple
attribute specifiedinput
elementtextarea
elementselect
element with its multiple
attribute specifiedoption
elements in the select
element's list of options that have their selectedness set to true.select
elementoption
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 >
これは次のようにレンダリングされるだろう:
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:
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"
を持つ同じフォームの別のフィールドを埋めることはユーザーエージェントbに対して適合しないだろう。前述の情報が指定される唯一の妥当な事前入力値は、それぞれ、"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日であることを知っている場合、わずかに異なる値を持つ以下のコントロールのすべてを事前入力しよう試み、この情報から駆動する。
| 2012-07 | 月状態が月/年の組み合わせのみを受け入れるので、日は破棄される。(Note that this example is non-conforming, because the autofill field name bday is not allowed with the Month state.) |
| July | The 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. |
| 7 | ユーザーエージェントは、フィールドのように、範囲1から12の数字を"July"に変換する。 |
| 6 | ユーザーエージェントは、フィールドのように、範囲0から11の数字を"July"に変換する。 |
| フォームが期待するものとして良い推測ができないため、ユーザーエージェントはフィールドに入力しない。 |
ユーザーエージェントは、ユーザーが要素のオートフィルフィールド名を上書き可能にしてもよい。たとえばページの作成者の異議にもかかわらず記憶されるおよび事前に入力されるよう許可するために"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公開オートフィル値を返さなければならず、設定時に、同じ名前のコンテンツ属性を反映しなければならない。
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.
指定された方向に指定された部分列をカバーするために選択を変更する。方向が省略された場合、方向がプラットフォームのデフォルト(なしまたは前方)になるようにリセットされる。
element.setRangeText(replacement [, start, end [, selectionMode ] ])
Support in all current engines.
新しいテキストとともにテキストの範囲を置換する。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:
If the element has a selection:
If the start of the selection is now past the end of the relevant value, set it to the end of the relevant value.
If the end of the selection is now past the end of the relevant value, set it to the end of the relevant value.
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.
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.
Support in all current engines.
The select()
method, when invoked, must run the following steps:
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.
Set the selection range with 0 and infinity.
The selectionStart
attribute's getter must run the following steps:
If this element is an input
element, and selectionStart
does not apply to this element, return null.
If there is no selection, return the code unit offset within the relevant value to the character that immediately follows the text entry cursor.
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:
If this element is an input
element, and selectionStart
does not apply to this element, throw an "InvalidStateError
" DOMException
.
Let end be the value of this element's selectionEnd
attribute.
If end is less than the given value, set end to the given value.
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:
If this element is an input
element, and selectionEnd
does not apply to this element, return null.
If there is no selection, return the code unit offset within the relevant value to the character that immediately follows the text entry cursor.
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:
If this element is an input
element, and selectionEnd
does not apply to this element, throw an "InvalidStateError
" DOMException
.
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:
If this element is an input
element, and selectionDirection
does not apply to this element, return null.
Return this element's selection direction.
The selectionDirection
attribute's setter must run the following steps:
If this element is an input
element, and selectionDirection
does not apply to this element, throw an "InvalidStateError
" DOMException
.
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:
If this element is an input
element, and setSelectionRange()
does not apply to this element, throw an "InvalidStateError
" DOMException
.
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:
If start is null, let start be zero.
If end is null, let end be zero.
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.
If direction is not identical to either "backward
" or "forward
", or if the direction argument was not given, set direction to "none
".
Set the selection direction of the text control to direction.
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:
If this element is an input
element, and setRangeText()
does not apply to this element, throw an "InvalidStateError
" DOMException
.
Set this element's dirty value flag to true.
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.
If start is greater than end, then throw an "IndexSizeError
" DOMException
.
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.
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.
Let selection start be the current value of the selectionStart
attribute.
Let selection end be the current value of the selectionEnd
attribute.
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.
Insert the value of the first argument into the text of the relevant value of the text control, immediately before the startth code unit.
Let new length be the length of the value of the first argument.
Let new end be the sum of start and new length.
Run the appropriate set of substeps from the following list:
select
"Let selection start be start.
Let selection end be new end.
start
"Let selection start and selection end be start.
end
"Let selection start and selection end be new end.
preserve
"Let old length be end minus start.
Let delta be new length minus old length.
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.)
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.)
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);
テキストの選択範囲を維持する一方で、テキストコントロールの開始時にテキストを追加するには、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);
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.)
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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:
Let controls be a list of all the submittable elements whose form owner is form, in tree order.
Let invalid controls be an initially empty list of elements.
For each element field in controls, in tree order:
If field is not a candidate for constraint validation, then move on to the next element.
Otherwise, if field satisfies its constraints, then move on to the next element.
Otherwise, add field to invalid controls.
If invalid controls is empty, then return a positive result.
Let unhandled invalid controls be an initially empty list of elements.
For each element field in invalid controls, if any, in tree order:
Let notCanceled be the result of firing an event named invalid
at field, with the cancelable
attribute initialized to true.
If notCanceled is true, then add field to unhandled invalid controls.
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:
Statically validate the constraints of form, and let unhandled invalid controls be the list of elements returned if the result was negative.
If the result was positive, then return that result.
Report the problems with the constraints of at least one of the elements given in unhandled invalid controls to the user.
User agents may focus one of those elements in the process, by running the focusing steps for that element, and may change the scrolling position of the document, or perform some other action that brings the element to the user's attention. For elements that are form-associated custom elements, user agents should use their validation anchor instead, for the purposes of these actions.
User agents may report more than one constraint violation.
User agents may coalesce related constraint violation reports if appropriate (e.g. if multiple radio buttons in a group are marked as required, only one error need be reported).
If one of the controls is not being rendered (e.g. it has the attribute set) then user agents may report a script error.
Return a negative result.
element.willValidate
HTMLObjectElement/willValidate
Support in all current engines.
フォームが送信される際に要素が認証される場合trueを返し、そうでなければfalseを返す。
element.setCustomValidity(message)
HTMLObjectElement/setCustomValidity
Support in all current engines.
HTMLSelectElement/setCustomValidity
Support in all current engines.
要素の検証に失敗するように、カスタムエラーを設定する。与えられたメッセージは、ユーザーに問題を報告する際にユーザーに表示されるメッセージである。
引数が空文字列である場合、カスタムエラーをクリアする。
element.validity.valueMissing
Support in all current engines.
要素が値を持たないが必須フィールドである場合trueを返し、そうでなければfalseを返す。
element.validity.typeMismatch
要素の値が正しい構文でない場合trueを返し、そうでなければfalseを返す。
element.validity.patternMismatch
要素の値が提供されたパターンとマッチしない場合trueを返し、そうでなければfalseを返す。
element.validity.tooLong
Support in all current engines.
要素の値が提供された最大長さより長い場合trueを返し、そうでなければfalseを返す。
element.validity.tooShort
Support in all current engines.
要素の値が空文字列ではなく、提供された最小長さより短い場合trueを返し、そうでなければfalseを返す。
element.validity.rangeUnderflow
要素の値が提供された最小値より短い場合trueを返し、そうでなければfalseを返す。
element.validity.rangeOverflow
要素の値が提供された最大値より長い場合trueを返し、そうでなければfalseを返す。
element.validity.stepMismatch
要素の値がstep
属性によって与えられる規則に合致しない場合trueを返し、そうでなければfalseを返す。
element.validity.badInput
Support in all current engines.
ユーザーエージェントが値に変換できないユーザーインターフェイスで入力をユーザーが提供される場合trueを返し、そうでなければfalseを返す。
element.validity.customError
要素がカスタムエラーを持つ場合trueを返し、そうでなければfalseを返す。
element.validity.valid
要素の値が妥当性問題を持たない場合trueを返し、そうでなければfalseを返す。
valid = element.checkValidity()
HTMLInputElement/checkValidity
Support in all current engines.
HTMLObjectElement/checkValidity
Support in all current engines.
HTMLSelectElement/checkValidity
Support in all current engines.
要素の値が妥当性問題を持たない場合trueを返し、そうでなければfalseを返す。後者の場合要素でinvalid
イベントを発火する。
valid = element.reportValidity()
HTMLFormElement/reportValidity
Support in all current engines.
HTMLInputElement/reportValidity
Support in all current engines.
要素の値が一切妥当性の問題を持たない場合はtrueを返す。そうでなければfalseを返し、要素でinvalid
イベントを発火させ、そして(イベントが中止されない場合)ユーザーに問題を報告する。
element.validationMessage
HTMLObjectElement/validationMessage
Support in all current engines.
要素が妥当性に対してチェックされた場合、ユーザーに表示されるエラーメッセージを返す。
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).
Support in all current engines.
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.
The setCustomValidity(error)
method steps are:
Set error to the result of normalizing newlines given error.
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 >
Support in all current engines.
The validity
attribute's getter must return a ValidityState
object that represents the validity states of this element. This object is live.
Support in all current engines.
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
Support in all current engines.
The control is suffering from a type mismatch.
patternMismatch
Support in all current engines.
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
Support in all current engines.
The control is suffering from an underflow.
rangeOverflow
Support in all current engines.
The control is suffering from an overflow.
stepMismatch
Support in all current engines.
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:
If element is a candidate for constraint validation and does not satisfy its constraints, then:
Fire an event named invalid
at element, with the cancelable
attribute initialized to true (though canceling has no effect).
Return false.
Return true.
The checkValidity()
method, when invoked, must run the check validity steps on this element.
ElementInternals/checkValidity
Support in all current engines.
The checkValidity()
method of the ElementInternals
interface must run these steps:
Let element be this ElementInternals
's target element.
If element is not a form-associated custom element, then throw a "NotSupportedError
" DOMException
.
Run the check validity steps on element.
The report validity steps for an element element are:
If element is a candidate for constraint validation and does not satisfy its constraints, then:
Let report be the result of firing an event named invalid
at element, with the cancelable
attribute initialized to true.
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.
Return false.
Return true.
The reportValidity()
method, when invoked, must run the report validity steps on this element.
ElementInternals/reportValidity
Support in all current engines.
The reportValidity()
method of the ElementInternals
interface must run these steps:
Let element be this ElementInternals
's target element.
If element is not a form-associated custom element, then throw a "NotSupportedError
" DOMException
.
Run the report validity steps on element.
The validationMessage
attribute's getter must run these steps:
If this element is not a candidate for constraint validation or if this element satisfies its constraints, then return the empty string.
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.
サーバーは、クライアント側の検証に依存すべきではない。クライアント側の検証は、悪意あるユーザーによって意図的にバイパスされ、古いユーザーエージェントまたは、これらの機能を実装しない自動化ツールのユーザーによって意図せずに回避されうる。制約検証機能は、あらゆる種類のセキュリティーメカニズムを提供することでなく、ユーザーの利便性を向上させることのみを意図する。
この節は非規範的である。
フォームが送信される際、フォーム内のデータは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--
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:
If the form has more than one field that blocks implicit submission, then return.
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
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
"):
If form cannot navigate, then return.
If form's constructing entry list is true, then return.
Let form document be form's node document.
If form document's active sandboxing flag set has its sandboxed forms browsing context flag set, then return.
If submitted from submit()
method is false, then:
If form's firing submission events is true, then return.
Set form's firing submission events to true.
For each element field in the list of submittable elements whose form owner is form, set field's user validity to true.
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:
Set form's firing submission events to false.
Return.
Let submitterButton be null if submitter is form. Otherwise, let submitterButton be submitter.
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.
Set form's firing submission events to false.
If shouldContinue is false, then return.
If form cannot navigate, then return.
Cannot navigate is run again as dispatching the submit
event could have changed the outcome.
Let encoding be the result of picking an encoding for the form.
Let entry list be the result of constructing the entry list with form, submitter, and encoding.
Assert: entry list is not null.
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.
Let method be the submitter element's method.
If method is dialog, then:
If form does not have an ancestor dialog
element, then return.
Let subject be form's nearest ancestor dialog
element.
Let result be null.
If submitter is an input
element whose type
attribute is in the Image Button state, then:
Let (x, y) be the selected coordinate.
Set result to the concatenation of x, ",
", and y.
Otherwise, if submitter has a value, then set result to that value.
Close the dialog subject with result.
Return.
Let action be the submitter element's action.
If action is the empty string, let action be the URL of the form document.
Let parsed action be the result of encoding-parsing a URL given action, relative to submitter's node document.
If parsed action is failure, then return.
Let scheme be the scheme of parsed action.
Let enctype be the submitter element's enctype.
Let formTarget be null.
If the submitter element is a submit button and it has a formtarget
attribute, then set formTarget to the formtarget
attribute value.
Let target be the result of getting an element's target given submitter's form owner and formTarget.
Let noopener be the result of getting an element's noopener with form, parsed action, and target.
Let targetNavigable be the first return value of applying the rules for choosing a navigable given target, form's node navigable, and noopener.
If targetNavigable is null, then return.
Let historyHandling be "auto
".
If form document equals targetNavigable's active document, and form document has not yet completely loaded, then set historyHandling to "replace
".
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.
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:
Let referrerPolicy be the empty string.
If the form
element's link types include the noreferrer
keyword, then set referrerPolicy to "no-referrer
".
If the form
has a non-null planned navigation, remove it from its task queue.
Queue an element task on the DOM manipulation task source given the form
element and the following steps:
Set the form
's planned navigation to null.
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.
Set the form
's planned navigation to the just-queued task.
The behaviors are as follows:
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.
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.
Plan to navigate to parsed action.
entry list is discarded.
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.
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.
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:
Set name to the result of converting name into a scalar value string.
If value is a string, then set value to the result of converting value into a scalar value string.
Otherwise:
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
".
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.
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):
If form's constructing entry list is true, then return null.
Set form's constructing entry list to true.
Let controls be a list of all the submittable elements whose form owner is form, in tree order.
Let entry list be a new empty entry list.
For each element field in controls, in tree order:
If any of the following are true:
field has a datalist
element ancestor;
field is disabled;
field is a button but it is not submitter;
field is an input
element whose type
attribute is in the Checkbox state and whose checkedness is false; or
field is an input
element whose type
attribute is in the Radio Button state and whose checkedness is false,
then continue.
If the field element is an input
element whose type
attribute is in the Image Button state, then:
If the field element is not submitter, then continue.
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.
Let namex be the concatenation of name and U+0078 (x).
Let namey be the concatenation of name and U+0079 (y).
Let (x, y) be the selected coordinate.
Create an entry with namex and x, and append it to entry list.
Create an entry with namey and y, and append it to entry list.
If the field is a form-associated custom element, then perform the entry construction algorithm given field and entry list, then continue.
If either the field element does not have a name
attribute specified, or its name
attribute's value is the empty string, then continue.
Let name be the value of the field element's name
attribute.
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.
Otherwise, if the field element is an input
element whose type
attribute is in the Checkbox state or the Radio Button state, then:
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
".
Create an entry with name and value, and append it to entry list.
Otherwise, if the field element is an input
element whose type
attribute is in the File Upload state, then:
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.
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.
Otherwise, if the field element is an input
element whose type
attribute is in the state and name is an ASCII case-insensitive match for "_charset_
":
Let charset be the name of encoding.
Create an entry with name and charset, and append it to entry list.
Otherwise, create an entry with name and the value of the field element, and append it to entry list.
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:
Let dirname be the value of the element's dirname
attribute.
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').
Create an entry with dirname and dir, and append it to entry list.
Let form data be a new FormData
object associated with entry list.
Fire an event named formdata
at form using FormDataEvent
, with the formData
attribute initialized to form data and the bubbles
attribute initialized to true.
Set form's constructing entry list to false.
Return a clone of entry list.
If the user agent is to pick an encoding for a form, it must run the following steps:
Let encoding be the document's character encoding.
If the form
element has an accept-charset
attribute, set encoding to the return value of running these substeps:
Let input be the value of the form
element's accept-charset
attribute.
Let candidate encoding labels be the result of splitting input on ASCII whitespace.
Let candidate encodings be an empty list of character encodings.
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.
If candidate encodings is empty, return UTF-8.
Return the first encoding in candidate encodings.
Return the result of getting an output encoding from encoding.
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:
Let list be an empty list of name-value pairs.
For each entry of entry list:
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).
If entry's value is a File
object, then let value be entry's value's name
. Otherwise, let value be entry's value.
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).
Append to list a new name-value pair whose name is name and whose value is value.
listを返す。
See URL for details on application/x-www-form-urlencoded
. [URL]
The multipart/form-data
encoding algorithm, given an entry list entry list and an encoding encoding, is as follows:
For each entry of entry list:
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).
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).
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]
Each entry in entry list is a field, the name of the entry is the field name and the value of the entry is the field value.
The order of parts must be the same as the order of fields in entry list. Multiple entries with the same name must be treated as distinct fields.
Field names, field values for non-file fields, and filenames for file fields, in the generated multipart/form-data
resource must be set to the result of encoding the corresponding entry's name or value with encoding, converted to a byte sequence.
For field names and filenames for file fields, the result of the encoding in the previous bullet point must be escaped by replacing any 0x0A (LF) bytes with the byte sequence `%0A
`, 0x0D (CR) with `%0D
` and 0x22 (") with `%22
`. The user agent must not perform any other escapes.
The parts of the generated multipart/form-data
resource that correspond to non-file fields must not have a `Content-Type
` header specified.
The boundary used by the user agent in generating the return value of this algorithm is the multipart/form-data
boundary string. (This value is used to generate the MIME type of the form submission payload generated by this algorithm.)
multipart/form-data
のペイロードを解釈する方法の詳細については、RFC 7578を参照のこと。[RFC7578]
The text/plain
encoding algorithm, given a list of name-value pairs pairs, is as follows:
Let result be the empty string.
For each pair in pairs:
Append pair's name to result.
Append a single U+003D EQUALS SIGN character (=) to result.
Append pair's value to result.
Append a U+000D CARRIAGE RETURN (CR) U+000A LINE FEED (LF) character pair to result.
Return result.
text/plain
形式を使用するペイロードは、人間可読であることを意図される。形式は不明瞭である(たとえば、値の末尾の改行と値でのリテラルの改行を区別する方法はない)ので、これらはコンピューターによって確実に解釈されない。
SubmitEvent
interfaceSupport in all current engines.
Support in all current engines.
[Exposed =Window ]
interface SubmitEvent : Event {
constructor (DOMString type , optional SubmitEventInit eventInitDict = {});
readonly attribute HTMLElement ? submitter ;
};
dictionary SubmitEventInit : EventInit {
HTMLElement ? submitter = null ;
};
event.submitter
Returns the element representing the submit button that triggered the form submission, or null if the submission was not triggered by a button.
The submitter
attribute must return the value it was initialized to.
FormDataEvent
interfaceSupport in all current engines.
Support in all current engines.
[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.
When a form
element form is reset, run these steps:
Let reset be the result of firing an event named reset
at form, with the bubbles
and cancelable
attributes initialized to true.
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).