MichaelCereda/react-native-form-generator

Not set Initial Value from this.state

andrebassi opened this issue · 8 comments

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

it return empty in input field ;/

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();

}

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

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 Thank you for your help!

@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 did you manage to fix your issue?