Text validator validates empty string
See original GitHub issueAre you requesting a feature, reporting a bug or asking a question?
Question? Bug?
What is the current behavior?
If you have a texfield with validation (minimum length) then when you start the survey, you are able to complete the survey since these values are empty.
However, if you type in the textfield, you can’t undo that action after the value has been set. Erasing the contents of the textfield won’t allow it to pass validation anymore.
What is the expected behavior?
I would expect that if a question is not marked as required, that it should be able to pass validation without having a value set.
Even if you set the value, but then later change the value (e.g. a textfield with minimum length validation), it should not hold up the survey unless marked as required.
It appears that if you have a minimum count on a checkbox then it essentially makes it required. You can’t complete the survey until that minimum requirement is met. Even though the question is not marked as required https://jsfiddle.net/mwrouse/qzfw87hL/4/
How would you reproduce the current behavior (if this is a bug)?
Make a survey with a textfield that has a minimum length > 0
Run the survey, don’t set any values and you will be able to complete the survey.
Run the survey again, type in the textbox field, and click out of the field. Then if you erase the contents you will fail the minimum length validation.
Provide the test code and the tested page URL (if applicable)
Tested page URL: https://jsfiddle.net/mwrouse/abo3eLdk/5/
Test code
var json = {
"completedHtml": "<p><h4>Thank you for sharing this information with us.</h4></p><p>Your name is: <b>{name}</b></p><p>Your email is: <b>{email}</b></p><p>This information is not in the survey data result:<b> {tempvar}</b></p>",
"pages": [
{
"name": "page1",
"elements": [
{
"type": "text",
"name": "question1",
"validators": [
{
"type": "text",
"minLength": 500000,
"maxLength": 0,
"allowDigits": true
}
]
}
],
"title": "Type, Click Out, and Erase = Failed Validation"
}
],
"triggers": [
{
"type": "setvalue",
"setToName": "name",
"setValue": "Jon Snow"
},
{
"type": "setvalue",
"setToName": "email",
"setValue": "jon.snow@nightwatch.com"
},
{
"type": "setvalue",
"setToName": "tempvar",
"setValue": "You have decided to use your current information.",
"isVariable": true
},
{
"type": "setvalue",
"setToName": "name"
},
{
"type": "setvalue",
"setToName": "email"
},
{
"type": "setvalue",
"setToName": "tempvar",
"setValue": "You have decided not to use your current information.",
"isVariable": true
}
]
};
window.survey = new Survey.Model(json);
survey.checkErrorsMode = 'onValueChanged';
survey.render("surveyElement");
Specify your
- browser: Chrome
- browser version: latest
- surveyjs platform (angular or react or jquery or knockout or vue): knockout
- surveyjs version: 1.8.55
Issue Analytics
- State:
- Created 2 years ago
- Comments:9 (4 by maintainers)
Top GitHub Comments
@mwrouse I found an old unit case where text validator returns error on checking an empty string. I have corrected it and added a new unit test. The fix will be available as well in v1.8.56.
Thank you, Andrew
@mwrouse We do not validate a question value if it is empty. However, entering the empty string should make the question value empty. I will take a look.
Thank you, Andrew