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

getValue() and Controlled 3rd party components #13

Closed
timothyallan opened this issue Dec 20, 2016 · 2 comments
Closed

getValue() and Controlled 3rd party components #13

timothyallan opened this issue Dec 20, 2016 · 2 comments

Comments

@timothyallan
Copy link

timothyallan commented Dec 20, 2016

Hi there,

I'm using the Material UI TextField component as a drop in replacement for your React Select demo and giving your library a spin. Few things that popped up that aren't necessarily anything to do with your library, but may be worthwhile thinking about :)

Here's the code:

import React from 'react'
import { FormInput } from 'react-form'
import TextField from 'material-ui/TextField';
export default ({ field, ...rest }) => {
  return (
    <FormInput field={field}>
      {({ setValue, getValue, setTouched }) => {
        return (
          <TextField
            {...rest} // Send the rest of your props to React-Select
            value={getValue() || ''} // Set the value to the forms value
            onChange={val => setValue(val.target.value) } // On Change, update the form value
            onBlur={() => setTouched()} // And the same goes for touched
            name="testext"
          />
        );
      }}
    </FormInput>
  );
}

Now, Material UI returns the event object in val. That caused an infinite loop in your removeNestedErrorValues function trying to parse that Object in return recurse(d, [].concat(_toConsumableArray(path), [i]));

Easily fixed once I figured out wtf was going on, but still, an infinite loop when passed bad data.

Secondly, I'm assuming getValue() returns undefined/null when there's no value. This causes the ol TextField is changing an uncontrolled input of type text to be controlled. error as soon as some text is entered.

Again easily fixed by the tweak above, but I'm wondering if getValue() should return '' rather than null.

Thoughts?

@tannerlinsley
Copy link
Collaborator

tannerlinsley commented Dec 20, 2016 via email

@timothyallan
Copy link
Author

Missed the default value param. Thanks!

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

2 participants