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

Example form gives "Warning: Input is changing an uncontrolled input of type ..." #150

Closed
shershen08 opened this issue Dec 2, 2016 · 2 comments

Comments

@shershen08
Copy link

After copying and running the example from examples/src/forms/Validation.js

The form is displayed , but when you try to changing field value I got following console warning:

Warning: Input is changing an uncontrolled input of type undefined to be controlled. Input elements should not switch from uncontrolled to controlled (or vice versa). Decide between using a controlled or uncontrolled input element for the lifetime of the component. 
More info: https://fb.me/react-controlled-componentsprint
Warning @ warning.js?8a56:36warning @ warning.js?8a56:60updateWrapper @ ReactDOMInput.js?1afa:131updateComponent @ ReactDOMComponent.js?ab8a:755receiveComponent @ ReactDOMComponent.js? 
...
@bsr203
Copy link

bsr203 commented Dec 2, 2016

can you try with setting the state so that all the field values are initialized. something like

 this.state = {
      value: {
      firstName: '',
      lastName: '',
      age: 0,
    },
 };

@shershen08
Copy link
Author

It worked out only if you set this in the child component, not in the wrapper one
I have AppFromWValidation -> Form, so doing this worked:

class Form extends React.Component {
  constructor(props) {
    super(props);
    let formValue = createValue({"schema":schema,
        value:  {
      firstName: '',
      lastName: '',
      age: 0,
    },
    onChange: this.onChange});
    
    this.state = {"formValue":formValue};
  }

while this

class AppFromWValidation extends React.Component {
  constructor(props) {
    super(props);

    this.onChange = this.onChange.bind(this);
    this.state = {
          value: {
      firstName: '',
      lastName: '',
      age: 0,
    }
    };
  }

did not

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

No branches or pull requests

2 participants