Question T4391
Visible to All Users

Setting isRequired to true on custom properties allows save even if the values are not filled

created 5 years ago

Hi,

I've added a couple of custom properties and have set isRequired to true.
But clicking on Save Survey makes an ajax call even if the values are not filled in.

Could you please suggest a solution on how to restrict Save if the values are not filled in.

Also is there a way to show custom messages like Survey Configuration has been saved successfully post AJAX call.

Thanks in advance.

Sandeep

Answers approved by surveyjs Support

created 5 years ago

Hello,

You can handle the https://surveyjs.io/Documentation/Survey-Creator?id=surveycreator#onQuestionAdded event and show a custom (3rd party) modal dialog with the fields need to be filled and check they are filled on this dialog closing.

Thanks, Serge
SurveyJS Team

    created 5 years ago

    Hello,
    You can handle survey.onCompleting event.

    JavaScript
    survey.onCompleting.add(function(sender, options) { options.allowComplete = isMyCustomPropertiesAllowComplete; });

    Another option is using a custom validation event.

    Thank you,
    Andrew
    SurveyJS Team

      Comments (3)

        Hi,

        Just wanted to understand if survey.onCompleting would be called when clicking on the Save Survey that would show up when we assign a function to creator.saveSurveyFunc.

        The idea is to have the questions and answers that are configured using SurveyCreator to be saved in our DB when clicking on Save Survey and as a part of that provide validations wherever required.

        Thanks,
        Sandeep

          Hello,
          I see. I decided that you are asking about SurveyJS Library and not about SurveyJS Creator, since I see that you do not have a license for using SurveyJS Creator.
          We do not allow to enter a invalid data if a survey creator user, for example, remove all data from a required property or enter a data that raise an error on validation, that raise, for example on creator.onPropertyValidationCustomError. In this case SurveyJS Creator leave old data in these properties.
          However, if your Survey JSON was initially invalid, then we do not show any error and save it as it is. From UI point of view, it would be strange, if a survey creator user, for example, add a new question on the page and on saving he would get an error. It would definitely confuse him.
          The idea that you provide to SurveyJS Creator a correct Survey JSON and we return you on saving the correct Survey JSON, do not allow survey creator to enter invalid data. Of course before saving data into your DB, you can go though all elements of editing survey, please use creator.survey property to access the editing survey, and show an error outside the SurveyJS Creator and ask a user to fix problems.

          The most our customers (developers) are using "auto save" functionality, and in this case, the only good UI solution, is to provide the correct JSON from the beginning.

          Thank you,
          Andrew
          SurveyJS Team

            Hi,

            I agree on the fact that the JSON that needs to be set should be a valid one.
            As I mentioned earlier that there are a couple of custom properties which I have added that are nothing but few of the fields from the database.
            So when a user adds a new question or an answer it is required that these fields need to be provided some information before the save happens. What I want to have here is a null check so that if the user misses to enter the information for these properties the save doesn't continue and also provide the necessary validation message under these custom properties.

            Lastly just wanted to let you know is that we are still exploring your library and have learned that it suits most of our requirement. We would have the license in place very soon.

            Thanks,
            Sandeep