formio / formio.js

JavaScript powered Forms with JSON Form Builder
https://formio.github.io/formio.js
MIT License
1.88k stars 1.06k forks source link

Textfield component triggers validation when input has the value of 0 #5554

Closed molequetu closed 1 month ago

molequetu commented 6 months ago

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.

lane-formio commented 6 months ago

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.

molequetu commented 6 months ago

@lane-formio the reason i am not using number is this issue https://github.com/formio/formio.js/issues/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.

VikkiAlenn commented 6 months ago

@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.

https://github.com/formio/formio.js/assets/105641597/0fdb0d16-6e95-4e6a-ac08-fc6dbd5c24c6

olgabann commented 1 month ago

Thank you for your contribution. As this issue has been inactive for over 90 days, I will close it for now. If you'd like to reopen the issue, please reply and we can resume the triage process.