martin sanchez
martin sanchez

Reputation: 1

React Native doesn't execute onpress function

        for(var index in preguntas.questions) {
            var attr1 = preguntas.questions[index]
            console.log(sum + " ***********************************************pregunta" + attr1.text )
            for(var index2 in attr1.answers) {
            var attr4 = attr1.answers[index2];
            respuesta.push(
                <View key = {index2} >
                    <RadioButton   onPress={() =>  this.onSubmitPressed(index2)} >
                        <Text>{attr4}</Text>
                    </RadioButton>

                </View >
            )
            }
            questions.push(
                <View key = {index}>
                    <View>
                        <Text >{attr1.text}</Text>

                        {respuesta}
                    </View>
                </View>
            )
            var respuesta = [];
            /*for(var index55 in attr2.answers) {
                var attr4 = attr2.answers[index2];
                console.log(sum + " ***********************************************" + attr4 )
                respuesta.push(`enter code here`
                <View key = {index55}>
                    <View>
                        <Text >{attr4}</Text>
                    </View>
                </View>
                )
            }*/



        }

Good morning I'm trying to run the onpres function that is onSubmitPressed but it will not let me and I get the following error ReactNativeJS: NETWORK error: TypeError: undefined is not a function (evaluating 'this.onSubmitPressed (index2)')

The code is inside the renderMovie function If I could help with that greetings

Upvotes: 0

Views: 120

Answers (1)

Ali
Ali

Reputation: 663

So it looks like the onSubmitPressed is not defined, what you will need to do is declare that function in your component and then also bind(this) if you want to use the state and any other values inside your this.

onSubmitPressed(index2) {
  //Do whatever you would like on your submit
}

constructor(props) {
  super(props)
  this.state = {};
  this.onSubmitPressed = this.onSubmitPressed.bind(this);
}

Upvotes: 1

Related Questions