Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Formsy.Mixin: props name="objectA.keyB" does not produce { ObjectA: {keyB:"value"} } #159

Closed
ajaykurien opened this issue Jul 9, 2015 · 6 comments

Comments

@ajaykurien
Copy link

The documentation at https://github.com/christianalfoni/formsy-react/blob/master/API.md#name suggests that

<MyInputComponent name="email"/>
<MyInputComponent name="address.street"/>

should generate a "form model" with a nested object. {email: 'value', address: {street: 'value'}}.

But when using formsy-react 0.14.1 and react 0.13.3:

<Input
  name="textA.A"
  value=""
  label="Text"
  type="text"
  placeholder="Here is a text input."
  help="This is a required text input."
  required
/>
<Input
  name="TextB.B"
  value=""
  label="Text"
  type="text"
  placeholder="Here is a text input."
  help="This is a required text input."
  required
/>

produces the following in the console:

screen shot 2015-07-09 at 17 21 37

i.e. values for individual A and B (zero-length string in this example) but not textA.A or TextB.B.

I'd appreciate some guidance. A workaround seems to be to use mapping, but that will get unwieldy quickly.

Thanks!

@ajaykurien ajaykurien changed the title Formsy.Mixin: props name="nameA.nameB" does not produce object. Formsy.Mixin: props name="objectA.keyB" does not produce { ObjectA{keyB:"value"} } Jul 9, 2015
@ajaykurien ajaykurien changed the title Formsy.Mixin: props name="objectA.keyB" does not produce { ObjectA{keyB:"value"} } Formsy.Mixin: props name="objectA.keyB" does not produce { ObjectA{keyB:"value"} } Jul 9, 2015
@ajaykurien ajaykurien changed the title Formsy.Mixin: props name="objectA.keyB" does not produce { ObjectA{keyB:"value"} } Formsy.Mixin: props name="objectA.keyB" does not produce { ObjectA: {keyB:"value"} } Jul 9, 2015
@adamalbrecht
Copy link

+1 just ran into this

@Semigradsky
Copy link
Collaborator

Hi, this is fixed in new version #158

@ajaykurien
Copy link
Author

Thanks @Semigradsky, and to @christianalfoni for a superb library.

@adamalbrecht, a short term workaround courtesy of @garbin, detailed at https://github.com/christianalfoni/formsy-react/pull/153/files

src/main.js:

mapModel: function () {
    if (this.props.mapping) {
      return this.props.mapping(this.model)
    } else {
      return Object.keys(this.model).reduce(function (mappedModel, key) {

        var keyArray = key.split('.');
        var base = mappedModel;
        while (keyArray.length) {
          var currentKey = keyArray.shift();
          base = (base[currentKey] = keyArray.length ? base[currentKey] || {} : this.model[key]);
        }

        return mappedModel;

      }.bind(this), {});
    }
  },

@christianalfoni
Copy link
Owner

Will close this as it is fixed in new version coming soon, thanks for the feedback @ajaykurien :-)

@jaraquistain
Copy link

@christianalfoni Any idea when the next version containing this fix will be released?

@christianalfoni
Copy link
Owner

Release Candidate out now on React, right around the corner :-) Took a bit longer than I thought, but now it is really close!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants