Skip to content

clearedValue with empty string is equivalent to undefined. #1513

Description

@ssav7912

Scope: Form Renderer/FieldProperties

Description
The default behaviour of a form is to set a value to undefined when the user has cleared it. An API is provided to override this behaviour: https://www.data-driven-forms.org/schema/cleared-value. However, specifying clearedValue = "" is treated the same way as clearedValue = undefined, so that the field property does not appear in getState().values etc.

"" !== undefined, and I think it would be valid behaviour for a cleared text field to actually return an empty string as its value.

Schema

 fields: [
    {
      component: componentTypes.TEXT_FIELD,
      name: "field-with-empty-string-cleared-value",
      label: "Will be set to undefined when field is empty",
      clearedValue: "",
    },
    {
      component: componentTypes.TEXT_FIELD,
      name: "field-without-cleared-value",
      label: "Value will be undefined when field is empty",
    },
    {
      component: componentTypes.TEXT_FIELD,
      name: "field-with-other-cleared-value",
      label: "Value will be null when field is empty",
      clearedValue: null,
    },
  ],

Thanks!

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingrendererReact form renderer PR

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions