Question T9185
Visible to All Users

Check if the survey form values have changed

created 3 years ago

Hello,

Is there a way for me to check if the surveyjs form has been edited or values changed ?
I am using React and I wanna show the user a popup if he tries to leave without saving data.
Or is there any approach you would recommend?
I am currently using the onValuesChanged method and trying to compare the old values with the new ones.
But when saving the state if the form is edited the survey gets rerendered and values are lost.

Answers approved by surveyjs Support

created 3 years ago

Hello,
I am not sure I understand the issue. You can set a boolean flag onValueChanged event to true. If a question value is not changed, this event is not fired. On saving the data, you can set this flag to false and on leaving a page, you can check this boolean flag.

Thank you,
Andrew
SurveyJS Team