0

I am trying to use an additional function on submit as I usually did but it shows it's not a function.

confirmSubmission = () => { // This doesn't work either: confirmSubmission() {
    //doSomething();
}

onSubmission(survey, options) {
    this.confirmSubmission(); // here it says Uncaught error: confirmSubmission is not a function
}

The function I used:

return (<MyCOmponent model={model} onComplete={this.onSubmission}/>);

Other code that I have within onComplete executes fine if confirmSubmission is not there.

I have a similar code with another function which works perfectly fine in the same component:

componentDidMount() {
    this.loadData(); // This works
}

loadData() {
    doSomething();
}

I am confused why it doesn't like the confirmSubmission call. Any ideas?

2 Answers 2

2

Try replacing

onSubmission(survey, options)

with an arrow function, it's the famous "this" issue

Sign up to request clarification or add additional context in comments.

Comments

0

You must have forgotten to bind the this context to onSubmission

constructor(/*...*/) {
  //..
  this.onSubmission = this.onSubmission.bind(this)
}

or

return (<MyCOmponent model={model} onComplete={this.onSubmission.bind(this)}/>);

1 Comment

Indeed, I was looking to register the wrong function. I don't quote understand why then it works without registering onSubmission when the additional function is not called in there?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.