-
-
Notifications
You must be signed in to change notification settings - Fork 303
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
Comments
The first problem is a small edge case o can handle when I jump back into
the code good find.
For controlled components that complain, use the default value parameter
for getValue. Eg getValue(field, '')
That should stop react from barking at undefined values.
…On Tue, Dec 20, 2016 at 12:10 AM Tim ***@***.***> wrote:
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?
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#13>, or mute the
thread
<https://github.com/notifications/unsubscribe-auth/AFUmCUG2M8BE11BBrDKMqYMoSf-y4tWPks5rJ39NgaJpZM4LRiA6>
.
|
Missed the default value param. Thanks! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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:
Now, Material UI returns the event object in
val
. That caused an infinite loop in yourremoveNestedErrorValues
function trying to parse that Object inreturn 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?
The text was updated successfully, but these errors were encountered: