Skip to content

How to create a form with an array of inputs #198

Description

@bytesoverflow

How would i go about creating a form that outputs:

<input name="name" type="text">
<input name="properties[0][var1]" type="text">
<input name="properties[0][var2]" type="checkbox">
<input name="properties[1][var1]" type="text">
<input name="properties[1][var2]" type="checkbox">

or alternatively if thats not possible:

<input name="name" type="text">
<input name="properties[var1]" type="text">
<input name="properties[var2]" type="checkbox">
<input name="properties[var1]" type="text">
<input name="properties[var2]" type="checkbox">

I need to add the array fields to the form dynamically based on the number of fields in the document i retrieve from mongo.

The data i need to bind to the form is in the following format:

{
name: 'xxxxx'
properties: [
    {var1: 'yyy', var2: true },
    {var1: 'zzz', var2: false}
 ]
}

I thought about creating a form using fields.array() for the properties attribute and using a custom widget that renders fields.object instead of fields.string but cant seem to get it working.

Is there a simple solution?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions