Skip to content

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

@wasd0109

Description

@wasd0109

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions