DateRange (and Date) Widget are not cleared, when document is cleared

When using the DateRange Widget, entering invalid data leads to a validation message to enter a correct value. That is fine and expected. Our customer wanted to have a reset button, to reset the form. After dispatching a setData with an empty document, the form is cleared, except for the DateRange widgets, which still have the invalid data entered, and still have the validation error.
How can i clear such a form completely?

Moin @jan-strong-spruce,

you can use two approaches to clear all fields, including validation error fields & messages.

1. Dispatching SET_DATA and SET_MESSAGE_STATE actions
Based on the click of your reset button, you could dispatch the SET_DATA action with an empty document to clear all non-error fields. For all validation error fields, like your DateRange field, you can dispatch a FORM-ENGINE-COMMAND action with the engineEvent SET_MESSAGE_STATE. The payload should be empty then.

payload: {
  messages: { 
  }
}

This will clear all fields which are erroneous and their corresponding validation messages.

2. Create and dispatch your custom action

  • Set up a custom reset action with a reducer
  • The reducer will handle the loadingState and reset the uiState slice
  • You could also use the preProcessDocument from the Form Engine if necessary

Kind regards,
Jan

Thanks a lot @jan-static-daemon , aproach 1 worked.