question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Text validator validates empty string

See original GitHub issue

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

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
andrewtelnovcommented, Jul 8, 2021

@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

1reaction
andrewtelnovcommented, Jul 8, 2021

@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

Read more comments on GitHub >

github_iconTop Results From Across the Web

Validate empty string in form - javascript
In myFunction you can simple add this code after creating a new instance of FormData : if (formData.get("urlName") === "") return ...
Read more >
Regular Expression to validate none empty string and double
please tell me how to implement Regular Expression such that it validate the text enter in a TextBox has to be a none...
Read more >
How To Add Validation For Empty Input Field with JavaScript
JavaScript validation for empty input field. Try to submit the form without entering any text. Name: Step 1) Add HTML: ...
Read more >
NotEmpty Validator - Laminas Docs
This validator allows you to validate if a given value is not empty. ... this validator will evaluate both the integer 0 and...
Read more >
JavaScript: HTML Form - checking for non empty field
You can write a JavaScript form validation script to check whether the required field(s) in the HTML form is blank or not.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found