Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Text validator validates empty string #3065

Closed
mwrouse opened this issue Jul 8, 2021 · 9 comments
Closed

Text validator validates empty string #3065

mwrouse opened this issue Jul 8, 2021 · 9 comments
Labels
Milestone

Comments

@mwrouse
Copy link

mwrouse commented Jul 8, 2021

Are 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
@mwrouse
Copy link
Author

mwrouse commented Jul 8, 2021

Just checking this programmatically with the textfield.

Doing survey.setValue('question1', '') by itself does nothing to fail the validation. I assume once you erase the textfield then it is equivalent to ''.

But if I do:

survey.setValue('question1', 'hey'); // Has minimum length 50000
survey.setValue('question1', ''); // Simulating empty textbox in UI

It will fail validation and prevent the survey from continuing/completing.

But doing

survey.setValue('question1', 'hey'); // Has minimum length 50000
survey.setValue('question1', null);

allows it to pass validation.

@andrewtelnov
Copy link
Member

@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

@mwrouse
Copy link
Author

mwrouse commented Jul 8, 2021

@andrewtelnov I assumed that is the case, but it appears something is wrong, since erasing the contents of a textbox will result in an empty string. And doing it programmatically shows that.

I also assume this is exists for textfields and such.

https://jsfiddle.net/mwrouse/qzfw87hL/4/ Shows that at least the checkbox questions are getting validated (on complete) when there is nothing set.

Thanks for your quick help!

@andrewtelnov andrewtelnov changed the title Questions Can't Go Back to Passing Validation Text validator validates empty string Jul 8, 2021
@andrewtelnov andrewtelnov added this to the v1.8.56 milestone Jul 8, 2021
@andrewtelnov
Copy link
Member

@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
Copy link
Author

mwrouse commented Jul 8, 2021

Thanks, I'm glad these are turning out to be rather easy, looks like that one was just a little logic error.

Should I open another bug for this:

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/

Or is that, for some reason, intended behavior? Or was it also solved with this?

@andrewtelnov
Copy link
Member

@mwrouse I am not sure about this one. I am afraid that some people is already used to have the current behavior.
However, I agree, it is not consistent. Do you have an issue with the current behavior?

Thank you,
Andrew

@mwrouse
Copy link
Author

mwrouse commented Jul 8, 2021

We produce an enterprise software, on one part of it customers have the ability to create surveys. So yes, I'm sure we will have issues.

There is nothing clear that makes it known that setting a validation requirement like that means that the question becomes required.

It would be a breaking change if introduced, but it would obviously make it more consistent. If you need the question to be answered, you have to mark it as required.

@andrewtelnov
Copy link
Member

@mwrouse I have checked unit tests and we do not have any unit case that checks answer count validator against an empty array. It means that I could make the changes. Here is the related issue.

Thank you,
Andrew

@mwrouse
Copy link
Author

mwrouse commented Jul 9, 2021

@andrewtelnov Just to confirm, but the fix you added will apply to all questions that have any kind of textfield for the input right? Comment and as well as multiple text?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants