react-native-form-generator icon indicating copy to clipboard operation
react-native-form-generator copied to clipboard

Not set Initial Value from this.state

Open andrebassi opened this issue 8 years ago • 8 comments

...InputField ref='homologadorNome' label='Homologador' placeholder='Informe o Nome' value={this.state.formData.homologadorNome}/>

andrebassi avatar Jan 19 '17 03:01 andrebassi

it return empty in input field ;/

andrebassi avatar Jan 19 '17 03:01 andrebassi

im getting the initial values from:

await fetch(base_url + '/select') .then((response) => { return response.json(); }) .then((row) => {

and after set:

this.setState({formData:data})

Fired in:

componentWillMount(){

  this.fetchData().done();

}

andrebassi avatar Jan 19 '17 03:01 andrebassi

How could I set an initial value from an api before render of component?

P.S: I really enjoyed using your project, but only missing a set information, fetching from a rest api when opening the view.

andrebassi avatar Jan 19 '17 03:01 andrebassi

??

andrebassi avatar Jan 26 '17 02:01 andrebassi

@andrebassi

I was struggling with the same thing. Take a look at https://github.com/MichaelCereda/react-native-form-generator/blob/master/examples/FormView.js#L99

You can set the field programmatically using the refs:

this.refs.theRefOfYourForm.refs.theRefOfYourInput.setValue("value");

mbeech avatar Jan 30 '17 16:01 mbeech

@mbeech Thank you for your help!

andrebassi avatar Jan 30 '17 17:01 andrebassi

@mbeech -> And how could this work before render() to load the information before View rendering?

Your suggestion works perfectly when a button is pressed.

andrebassi avatar Jan 30 '17 17:01 andrebassi

@andrebassi did you manage to fix your issue?

ccostel avatar Oct 25 '17 09:10 ccostel