question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Nesting forms, complex data structures

See original GitHub issue

I was wondering if there is a possibility of nesting forms to create complex data structures or if there is an easy way to implement that?

If the Form itself would implement the same interface as the Form element, we could nest them indefinitely and create complex hierarchical data structures with validation. Or maybe creating a special Input field is the way to go…

I tried around a little bit with creating my own Input element with sub elements, but that does not work because I don’t have access to the validation rules in an external component. For now I created a mapping function which can handle names like entity[property] and returns the value correctly, but that is not as nice, because all the nodes have to be inside the main form component. Also I cannot add validation rules and a sub form, like when I want to make a complete address required. When trying to create reusable form partials I get the error: Uncaught Error: Form Mixin requires component to be nested in a Form

I was thinking about something like that (simplified draft):

First create reusable form:

var AddressForm = React.createClass({
[...]
render: function(){
    return (
        <Formsy.Form {...this.props}>
             <input name="street"/>
             <input name="zip"/>
             <input name="city"/>
        </Formsy.Form>
    ); 
}
});

And then reuse that form as a field:

 <Formsy.Form>
   <input name="name"/>
   <input name="otherProperty"/>
   <AddressForm name="address"/>
</Formsy.Form>

Basically what I am trying to get from the form as a value is a complex data structure like that:

{
    name: 'Someclient',
    otherProperty: 123,
    address: {
        street: 'xyz',
        zip: 'xyz',
        city: 'xyz'
    }
}

Any thoughts on what’s the best way to approach that? I think it would be a really great feature, I’d be happy to help implementing.

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Reactions:1
  • Comments:33 (12 by maintainers)

github_iconTop GitHub Comments

5reactions
Semigradskycommented, Dec 10, 2015

@dsteinbach you can not nesting forms: http://www.w3.org/TR/2011/WD-html5-20110525/forms.html#the-form-element

Content model: Flow content, but with no form element descendants.

1reaction
klis87commented, Jul 3, 2017

@Semigradsky Nested form could be displayed as div, then we could check whether part of a form is valid or not - this functionality is present in many form libraries, including Angular and Redux Form and it is implemented without any violation of HTML5 spec.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Nested Data Structures and Nested Loops | by Diane Tunnicliffe
I have found that it can help a lot to break it down and pay attention to just one loop at a time...
Read more >
Arrays and nested data - Remix Validated Form
Arrays and nested data. In additional to handling regular repeated fields, this library can also handle more complex arrays and nested data in...
Read more >
How to Deal with Complex Data Structures - OutSystems
Let's look at two scenarios. Scenario 1: Recursive Nested Structure with Undefined Depth. A recursive structure is one that holds itself as an ......
Read more >
How to structure aria/accessibility on complex nested form ...
To structure forms, the <fieldset> element along with a <legend> should be used. This element has a group role, which will not add...
Read more >
Complex Rails Forms with Nested Attributes - SitePoint
Read Complex Rails Forms with Nested Attributes and learn with SitePoint. Our web development and design tutorials, courses, and books will ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found