formio.js icon indicating copy to clipboard operation
formio.js copied to clipboard

TextField is not treating space as empty value when performing Required check

Open wasd0109 opened this issue 1 month ago • 0 comments

Describe the bug The TextField component does not seems to be treating space character " " as empty value, which was the case in previous version ("formiojs": "4.13.10")

Version/Branch version: 5.0.1

To Reproduce Steps to reproduce the behavior:

  1. Create empty form
  2. Add TextField component
  3. Set TextField -> Validation -> Required to checked
  4. Add Button component
  5. Set Button -> Disable on Form Invalid to checked
  6. Open the form
  7. Enter space in the TextField

Expected behavior: Required area is displayed, and the Submit button remain disabled Actual behavior: the Submit button is enabled

minimum form components for replication "components": [ { "input": true, "tableView": true, "label": "Text Field", "type": "textfield", "key": "textField", "validate": { "required": true } }, { "input": true, "showValidations": false, "tableView": false, "label": "Submit", "type": "button", "disableOnInvalid": true, "key": "submit", "saveOnEnter": false } ],

Screenshots now:

Image

previous:

Image

Additional context I believe this to be due to the switch from component defined validation in previous version which include trim to input value https://github.com/formio/formio.js/blob/v4.13.1/src/validator/rules/Required.js#L9 https://github.com/formio/formio.js/blob/v4.13.1/src/components/textfield/TextField.js#L165

to centralized validation definition which does not perform trim before the validation

https://github.com/formio/core/blob/e21741ae1c927cb43528cb1de44e08e85d2ea843/src/process/validation/rules/validateRequired.ts#L50

wasd0109 avatar Dec 03 '25 08:12 wasd0109