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

unexpected value from getValue() in custom input example #46

Closed
chuan137 opened this issue Mar 15, 2017 · 2 comments
Closed

unexpected value from getValue() in custom input example #46

chuan137 opened this issue Mar 15, 2017 · 2 comments

Comments

@chuan137
Copy link

Hello,

Here is my code, <TextField/> is from material ui. The problem is that, the input field shows the field name as default value. The behaviour of getValue(field, '') is not expected. I use getValue() || '' as a work around, which works fine.

but it would be nice to find out why the behaviour, thanks.

import { Form, FormInput } from 'react-form';
const InputField = ({field, ...rest}) => {
  return (
    <FormInput field={field}>
      {({setValue, getValue}) => {
        
        console.log(field);    /* field is 'email' */
        console.log(getValue(field, ''));   /* expect empty string on initial, but 'email' is logged */  

        return  (
          <TextField 
            value={getValue(field, '')}
            onChange={(e,v) => setValue(v)}
            {...rest} />
        )
       }}
    </FormInput>
  );
}
@mintyPT
Copy link

mintyPT commented Jun 29, 2017

Same issue here. Did you found your problem?

@tannerlinsley
Copy link
Collaborator

Remember, when getValue is used inside a FormInput or anywhere that a field prop is passed, it is automatically bound to that field. So you would simply call getValue(defaultValue) instead of getValue(field, defaultValue).

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

3 participants