question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to reset / clear a survey so it can be taken multiple times?

See original GitHub issue

Are you requesting a feature, reporting a bug or asking a question?

Asking a Question

I’m just wondering how to reset a survey once it’s done. I’m using the react version (1.1.12). I have a survey that I want to use multiple times on a single page. I just need to know how to reset the form.

What is the current behavior?

When the form is completed, it shows the completion html (or nothing, if I specify showCompletedPage={false}).

What is the expected behavior?

My desired behavior is that once the user completes a survey, the survey resets to its original blank state and the user can fill it out again.

P.S. Thanks for building survey.js, it’s really nice. I especially like the survey creator website. All around well done!

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
Aaronikcommented, Oct 21, 2019

I’d like to bump this, it’s still causing issues for me and my product. How can I clear the survey in React?

1reaction
Aaronikcommented, Oct 9, 2019

Does that survey variable come from a React ref?

When I use a react ref, the render() function does work (The survey is coming back, yay!), but clear() is having no effect (The values are all still present in the survey fields).

Here is my code:

import React from 'react'
import { Survey as SurveyReact } from 'survey-react'
import Container from 'react-bootstrap/Container'

type TProps<TSurveyResult> = { 
  json: Object
  onComplete: (json: TSurveyResult) => void
}

export default class Survey<TSurveyResult> extends React.Component<TProps<TSurveyResult>, {}> {
  private survey = React.createRef<SurveyReact>()

  private onComplete = (resp: { data: TSurveyResult }) => {
    const surveyJson = resp.data

    // Property 'survey' is protected and only accessible
    // within class 'Survey' and its subclasses.
    // However, this is how you access survey, as per
    // https://github.com/surveyjs/survey-library/issues/1855.
    // @ts-ignore
    this.survey.current.survey.clear()
    // @ts-ignore
    this.survey.current.survey.render()

    this.props.onComplete(surveyJson)
  }

  render() {
    return (
      <Container>
        <SurveyReact
          ref={this.survey}
          showCompletedPage={false}
          json={this.props.json}
          onComplete={this.onComplete}
        />
      </Container>
    )   
  }
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

Clearing or Deleting Responses - SurveyMonkey Help
Go to the Collect Responses tab of your survey. Click . to the right of the Collector. Click Clear responses. Deleting All Responses...
Read more >
Retake Survey Link - Qualtrics
Retake survey links allow you or your respondent to go back into a survey response and edit it after it has been submitted....
Read more >
How to stop respondents from taking a survey more than once
If you are using custom variables in the survey URL, then you can prevent them from taking the survey multiples times by turning...
Read more >
Adjust your form or quiz settings in Microsoft Forms
With Microsoft Forms, you can create a form (such as a survey or poll) or quiz ... to edit settings, and then select...
Read more >
My respondents can't take my survey. How can I fix this?
1 Select your survey. · 2 From the left-hand navigation, click Settings, then Survey Behavior. · 3 Click Edit. · 4 In the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found