react-native-simple-radio-button icon indicating copy to clipboard operation
react-native-simple-radio-button copied to clipboard

React Native RadioForm adding initial state from Firebase

Open tiagodprovenzano opened this issue 7 years ago • 3 comments

I'm trying to create an assessment sheet that keeps records of students skills.I'm trying to use RadioForm in order to keep these records and easily edit them, but I dont seem to be able to set an initial value for radio form from my firebase data.

` <View style={estilos.login}> <View style={{backgroundColor:'#000', padding:10}}> <Text style={{color:'#ccc', fontWeight: 'bold', fontSize:20}}>{this.props.nomeAluno}</Text> </View> <ListView enableEmptySections dataSource={ this.fonteDeDados } renderRow={data => {

                    return(
                    
                        <View style={{ flexDirection: 'row' , width:300, borderWidth:1, borderColor:'#000' }}>
                        <View style= {{backgroundColor:'#fff', padding:3, alignItems:'flex-start', justifyContent:'center', flex:1.5}}>
                            <Text style={{margin:2}}>{data.criterio}</Text>
                        </View>        
                        <RadioForm
                            radio_props={[{label: 'Above', value: '0' },
                            {label: 'Meeting', value: '1' },{label: 'Below', value: '2'}]}
                            initial= { this.initial(caminho) }
                            formHorizontal={true}
                            style={{padding:10}}
                            labelHorizontal={false}
                            onPress={(value) => {this._clicaOption(data.criterio, value),  console.log(this.props.caminho)}}
                        />`

My initial function looks like this: `initial(index){ if (index){ return index; }else{ var int = 2; return int; }

}`

"Caminho" is defined like this in mapStateToProps:

let caminho = 'data.' + nomeGrupo + '.' + nomeAluno + '.index'

Would Appreciate the help.... tks!

tiagodprovenzano avatar Nov 15 '17 19:11 tiagodprovenzano

same issue. did you find a solution here? I cant make use of this.refs.radioForm.updateIsActiveIndex(0) neither @tiagodprovenzano

cosmosof avatar Jan 11 '18 05:01 cosmosof

@cosmosof For what it's worth, I had trouble getting updateIsActiveIndex working too but I figured out a solution.

The documentation doesn't tell you this but you need to set a ref attribute on the <RadioForm> component and give it the name "radioForm" in order to get this to work.

 <RadioForm ref="radioForm" ....  />

Then you can make a call to updateIsActiveIndex like this:

 this.refs.radioForm.updateIsActiveIndex(0)

gingerbeardstudios avatar Feb 22 '18 04:02 gingerbeardstudios

I was having trouble calling updateIsActiveIndex on my RadioForm ref so I was able to asynchronously update the form's active index by directly setting the state by doing:

radioForm.current.state.is_active_index = 0

charkour avatar Mar 15 '20 00:03 charkour