Web Components
The setFormValue() method of the ElementInternals interface sets the element's submission value and state, communicating these to the user agent.
Syntax
setFormValue(value)
setFormValue(value, state)
Parameters
value- : A File, a string, or a FormData as the value to be submitted to the server.
state- : A File, a string, or a FormData representing the input made by the user. This allows the application to re-display the information that the user submitted, in the form that they submitted it, if required.
[!NOTE] In general,
stateis used to pass information specified by a user, thevalueis suitable for submission to a server, post sanitization. For example, if a custom element asked a user to submit a date, the user might enter "3/15/2019". This would be thestate. The server expects a date format of2019-03-15, the date in this format would be passed as thevalue.
Return value
Undefined.
Exceptions
NotSupportedErrorDOMException- : Thrown if the element does not have its
formAssociatedproperty set totrue.
- : Thrown if the element does not have its
Examples
In the following example, a checkbox custom element sets on as the value to send to the server, and checked as the state.
this.internals_.setFormValue("on", "checked");
Specifications
Browser compatibility
来源:MDN Web Docs / Mozilla 贡献者 · 作者与贡献记录 · CC BY-SA 2.5。离线整理了版式、链接和媒体显示。
