formio / formio.js

JavaScript powered Forms with JSON Form Builder

Home Page:https://formio.github.io/formio.js

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Textfield component triggers validation when input has the value of 0

molequetu opened this issue · comments

Describe the bug
Hello, I use a textfield component from which I use validation for required and a regex pattern in order to allow only numbers
Here is the configuration of the textfield
{ "label": "Last Year's Income", "tableView": true, "type": "textfield", "validate": { "required": true, "pattern": "[0-9]*", "customMessage": "Please provide only numbers" }, "key": "parent2PreviousYearIncome", "input": true },
In the first time I am able to save using as input the value 0. After re-render of the form with the data, with no changes made in the textfield, when i press save / submit, validation gets trigger for unknown reason. I tried remove the regex pattern for numbers, but still the validation gets triggered as the field is required although it has the value 0. If I re-enter value 0 in the textfield it gets saved correctly.

The validation gets triggered only for the value 0, using other values e.g 1 does not trigger it.

Version/Branch
^4.17.1

To Reproduce
Steps to reproduce the behavior:

  1. Create a textfield with validation required
  2. Put the value 0 and save - success
  3. Reload the form, click save without changes and the validation gets triggered althoug it has value

Expected behavior
Textfield should treat 0 as a value and not trigger validation.

Screenshots
If applicable, add screenshots to help explain your problem.

Additional context
Add any other context about the problem here.

I suppose I'm curious why you aren't just using a number component here. If someone would like to look into this we are always willing to review contributions, but the use-case here is unclear to me and I don't see us resourcing it.

@lane-formio the reason i am not using number is this issue #4032
My first option ofc was to use a Number component but as referenced it has a problem in posting null values.

@lane-formio what is exaclty unclear to you? If i can help tell me.

@molequetu Could you try to reproduce the same scenario in formioJS 4.19.0, for example?
Or, please, check the steps in our video and let us know if we are reproducing that correctly.

chrome_eXXktzacNu.mp4