react-forms icon indicating copy to clipboard operation
react-forms copied to clipboard

clearedValue with empty string is equivalent to undefined.

Open ssav7912 opened this issue 9 months ago • 3 comments

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!

ssav7912 avatar Jun 19 '25 02:06 ssav7912