Issue T2242
Visible to All Users

Prevent saving survey if missing required properties

created 6 years ago

I was hoping that adding a custom survey property and setting isRequired to true for that custom property would prevent users from saving a survey without filling out that property, and surface the problem in a user-friendly way.

Perhaps I'm doing something wrong? I tried both these methods:

JavaScript
SurveyKo.Serializer.addProperty("survey", { name: "name:text", isRequired: true });

and

JavaScript
SurveyKo.Serializer.addProperty("survey", { name: "name:text" }); SurveyKo.Serializer.findProperty("survey", "name").isRequired = true;

In either case, without filling out the survey name property in the property grid, the saveSurveyFunc function still gets invoked without surfacing any error.

Answers approved by surveyjs Support

created 6 years ago

Hello Sami,
Survey Creator will not allow to Apply the changes inside Survey Editor, if survey name is empty. If initially the survey.name is not empty, then the user will not be able to save the survey with empty name.
Set the survey.name on loading survey definition, if the survey.name is empty.

Thank you,
Andrew
SurveyJS Team

    Other Answers

    created 6 years ago (modified 6 years ago)

    As it turns out, only the latter method behaves similarly to what you describe:

    JavaScript
    SurveyKo.Serializer.findProperty("survey", "name").isRequired = true;

    However, while clearing the property value in the property editor and then clicking "Apply" or "Ok" does surface the problem in an alert, it doesn't prevent the property from being cleared. Clicking "Cancel" and then "Save Survey" will go through and save the survey with the cleared property value that is supposed to be required.

    May I suggest revisiting this behavior? I feel a property marked as required should prevent the user from saving the survey, whether it was just left empty or manually cleared.

      Show previous comments (7)

        I changed the code sightly. See my plunker fork

        Steps to reproduce:

        • In the object dropdown of the Advanced tab, click Survey
        • Next to the required name property, click Edit
        • In the modal property editor, clear the text from the textarea input
        • Click OK or Apply
        • Notice the error alert indicating the property is required
        • Click Cancel
        • Notice in the property grid that the property value was cleared nonetheless
        • Click Save Survey
        • Notice that, despite being marked as required, the survey name was not serialized (because it was cleared)

          Yes, I will take a look.

          Thank you,
          Andrew
          SurveyJS Team

            Hello Sami,
            I have fixed the issue via this commit.
            We will include the fix in the next minor update. We release every week, commonly on Tuesday.

            Thank you,
            Andrew
            SurveyJS Team