Proposal: Introduce <field-array> and <field-object> for Native Array/Object Handling in HTML Forms. #10948
Labels
addition/proposal
New features or enhancements
needs implementer interest
Moving the issue forward requires implementers to express interest
What problem are you trying to solve?
Proposal: Introduce
<field-array>
and<field-object>
for Native Array and Object Handling in HTML FormsAbstract
HTML forms currently lack a native mechanism for handling complex data structures such as arrays and objects. Developers are forced to rely on workarounds like naming conventions (e.g.,
name="person[0][name]"
) or JavaScript-based solutions to collect and submit such data. This proposal introduces two new elements,<field-array>
and<field-object>
, to allow for intuitive and declarative handling of arrays and objects within forms, making complex data collection seamless and standardized.Problem Statement
HTML forms are designed for simple key-value pair submissions. When developers need to submit arrays or nested objects, they must:
name="object[array][key]"
, which can be error-prone and verbose.This lack of native support leads to inconsistencies in implementation, increased development effort, and barriers to accessibility and standardization.
What solutions exist today?
Proposed Solution
Introduce two new HTML elements:
<field-array>
: Defines a group of elements representing an array.<field-object>
: Encapsulates a set of key-value pairs within an array.These elements would automatically group and structure form data into arrays and objects, serialized appropriately during form submission.
How would you solve it?
Example Usage
Simple Array Submission:
Submitted Data:
Array of Objects:
Submitted Data:
Benefits
Implementation Details
<field-array>
and<field-object>
elements into structured JSON-like data.<field-array>
can includerequired
andmaxlength
attributes to validate array length.<field-object>
inherits validation rules from its child inputs.Anything else?
Conclusion
The introduction of
<field-array>
and<field-object>
has the potential to revolutionize how complex data is collected and submitted via HTML forms. By addressing a long-standing limitation, this proposal would greatly enhance the power and usability of web forms, reducing the reliance on JavaScript and workarounds while improving developer productivity and user experience.The text was updated successfully, but these errors were encountered: