0
How can I make so that when the "title" of the task is selected through the Picker it fills my other fields belonging to this task and can update my data? thanks for your help ;)
export default class atualizaranuncio extends Component {
constructor() {
super();
this.state = {
status: '',
titulo: [],
titulo_selecionado: ""
};
firebase.auth().onAuthStateChanged((user) => {
if (user) {
firebase.database().ref('Tarefas').child(user.uid).once('value', (snapshot) => {
let state = this.state;
state.titulo = [];
snapshot.forEach((childItem) => {
state.titulo.push({
key: childItem.key,
titulo: childItem.val().titulo
});
});
this.setState(state);
});
}
});
}
render() {
return (
<View style={styles.container}>
<Text style={styles.logoText}>Atualizar o Anuncio</Text>
<Text>{'\n'}</Text>
<Text style={styles.texto}>Titulo do Anuncio:</Text>
<Picker
selectedValue={this.state.titulo_selecionado}
style={styles.picker}
onValueChange={(itemValue, itemIndex) => this.setState({ titulo_selecionado: itemValue })}>
{this.state.titulo.map((item, index) => {
return (
<Picker.Item label={item.titulo} value={item.titulo} key={index}/>
);
})}
</Picker>
<Text style={styles.texto}>Descrição do Anuncio:</Text>
<TextInput style={styles.inputBox}
underlineColorAndroid='rgba(0,0,0,0)'
placeholder="Descrição"
placeholderTextColor="#ffffff"
selectionColor="#fff"
/>
<Text style={styles.texto}>Valor do Anuncio:</Text>
<TextInput style={styles.inputBox}
underlineColorAndroid='rgba(0,0,0,0)'
placeholder="R$0000,00"
placeholderTextColor="#ffffff"
selectionColor="#fff"
keyboardType="number-pad"
/>
<Text style={styles.texto}>Status:</Text>
<Picker
selectedValue={this.state.status}
style={styles.picker}
onValueChange={(itemValue, itemIndex) =>
this.setState({ status: itemValue })
}>
<Picker.Item label="Não realizado" value="1" />
<Picker.Item label="Realizado" value="0" />
</Picker>
<TouchableOpacity style={styles.button}>
<Text style={styles.buttonText}>Atualizar Anuncio</Text>
</TouchableOpacity>
</View>
);
}
}
It is working, but he does not exchange the Status Picker that in the bank is 1 or 0, how do I get him to bring the right Picker?(Because I leave it with value 1 and 0 pq I believe that goes to the bank with this value, so how to display the right and to keep the same time for when I click update it work?) but I thank you for your help!! you know how to+!!
– Nuck
If the problem is only in status Picker, and if you are getting the value when mounting the title array, I think the problem should be the format. First try to convert the value to integer (status: parseint(your field)). If the error persists, try converting to string (status: String(your field))
– Bins
Thank you very much!!!! <3
– Nuck