formio.js icon indicating copy to clipboard operation
formio.js copied to clipboard

Select field value is empty string in stead of null

Open bobvanhesse opened this issue 10 months ago • 3 comments

Describe the bug The Select component uses "" as the value when no option is selected. I would have expected null, which integrates a lot better with other tools (camunda in my particular case). It makes a difference, because null would mean no value is set, which is correct, whereas an empty string is seen as a value.

Version/Branch v5.0.1

To Reproduce Steps to reproduce the behavior:

  1. Create a new form
  2. Add a select component
  3. Configure a couple of values to choose from
  4. Select a value
  5. Click the cross to empty the value

Expected behavior The value will be equal to null to indicate that no value was selected

Actual behavior The field's value is equal to "" (empty string)

bobvanhesse avatar Feb 10 '25 08:02 bobvanhesse

This is expected behavior. https://es5.github.io/#x9.2

lane-formio avatar Feb 26 '25 14:02 lane-formio

The resulting json with "" as a value in stead of null is not necessarily processed in javascript (ES5) as you suggest, but in this case in Java. If it was expected behaviour I would expect to find this in the documentation. Please reopen the ticket.

bobvanhesse avatar Feb 26 '25 16:02 bobvanhesse

This may have been fixed with my pull request @ https://github.com/formio/formio.js/pull/6054 and in particular the change made here https://github.com/formio/formio.js/pull/6054/files#diff-05d41a5d854049f92f62772ee82f295d614534d5f4f0717b3ec30c69dfc3a7f5R2905. Before it would set the default value to empty string instead of the components "emptyValue". Please let us know if this is indeed resolved for you.

travist avatar Mar 19 '25 20:03 travist