Skip to content

clearedValue with empty string is equivalent to undefined. #1513

@ssav7912

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!

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