Hi team,
We are having issues in implementing Validation of SurveyJS which we set in Designer.
We have set the Validation property as "OnValueChanged (After an Answer is Changed)" in Designer. But the same validation is not reflecting for properties which are set "IsRequired".
We have shared the sample application, please refer that.
Thanks,
Santosh
Hi Santosh,
Thank you for sharing a sample.
Survey validation for required questions runs when a user attempts to move to the next page without submitting a question:

Would you please elaborate on the expected behavior?
We want to use these two options in Validation, and need to know how they differ from "On Next Page Change"?
For example - If we select "After an answer is changed" option for a required question, say Dropdown. It should throw error instantly whenever we delete the selected response. If that's the case, it is not working the expected way.
In our case, when we set "After an answer is changed". it is not throwing error instantly instead throwing after page change which should be case for "OnNextPageChange" option.
Please let me know the expected behavior of all 4 options.
Hello Santosh,
Unlike dropdown, checkbox question is different. You never know when the user stop to customize the question, because a user can set/unset an item at any moment when it is on the current page. That is why we have the code that makes sure that we validate checkbox on "next page"/"complete" actions only.
Thank you,
Andrew
SurveyJS Team
Hi Andrew,
I see the same behavior for other type of controls too. Please check with below JSON.
{
"logoPosition": "right",
"pages": [
{
"name": "page1",
"elements": [
{
"type": "checkbox",
"name": "question1",
"isRequired": true,
"choices": [
"Item 1",
"Item 2",
"Item 3"
]
},
{
"type": "dropdown",
"name": "question2",
"isRequired": true,
"choices": [
"Item 1",
"Item 2",
"Item 3"
]
},
{
"type": "text",
"name": "question3",
"isRequired": true
}
]
}
],
"checkErrorsMode": "onValueChanged"
}
Thanks,
Santosh
Hello Santosh,
Indeed. It works for "onValueChanging" and doesn't work for "onValueChanged". I will take a look and comeback. Here is the related example.
Thank you,
Andrew
SurveyJS Team
Hello Santosh,
I have tried to implement this functionality and found that we have several unit tests that checks that we do not show error for required value immediately even if error mode is "onValueChanged".
Several our customers requested this exact behavior. The behavior, that you want, was annoying for their end-users.
What is the reason you want to have this behavior?
Thank you,
Andrew
SurveyJS Team
Hi Andrew,
As the name suggests "onValueChanged", it should validate the question immediately. Either it should given a different name or it should validate the question immediately. We have a open defect related to this feature raised by our Quality team.
As you said this behavior is added for several set of customers but since other customers don't have any idea of this behavior it is making confusion at our end.
Thanks,
Santosh
You have the point. It makes sense when a user have just left an input. The problem, that sometimes value is changed by trigger or from the code (for example on loading previous data) and showing error for empty field in this case is not a good approach.
Let me think about it. I am not sure we can distinguish setting value via code or by user input. I will be back on this.
Thank you,
Andrew
SurveyJS Team
I have updated the issue on GitHub that I have created yesterday.
We will discuss it. It may take a while.
Thank you,
Andrew
SurveyJS Team
Hello Santosh,
We will show the required error if a user makes a required field empty and before it was not empty. We do not show an error if the value was set into survey.data or complex questions like matrix dynamic or panel dynamic.
Thank you,
Andrew
SurveyJS Team
As per your comment "We will show the required error if a user makes a required field empty and before it was not empty", I tried to set the value to textbox type of question which is required then erased the value but it did not thrown the error.
Thanks,
Santosh
Hi Santosh,
Please ensure that you updated your SurveyJS libraries 10 the most recent version (v1.9.103).
package.json
"survey-angular-ui": "1.9.103", "survey-core": "1.9.103"
Also, please verify that the
survey.checkErrorsMode
property is set to"onValueChanged"
.{ checkErrorsMode: "onValueChanged", pages: [ { name: "Name", elements: [ { type: "text", name: "FirstName", title: "Enter your first name:", isRequired: true, defaultValue: "Jane" } ] } ] }
I created the following demo for your reference and confirmed that it performs as expected: View Demo
We look forward to your results.