directus icon indicating copy to clipboard operation
directus copied to clipboard

Files interface: [] is not considered the same as null for mandatory field, and cannot sidestep with validation

Open shipsides-sparknel opened this issue 3 years ago • 1 comments

Describe the Bug

I have a form with a Files interface. By default it is a mandatory field on creation, but this can be sidestepped by toggling a checkbox triggering a condition making it temporarily non mandatory. Once the item is created, the checkbox is automatically removed via flow so that the next open will force the user to upload.

The Files interface changes null to [] on creation. This means if you update the form without uploading a file, it incorrectly passes validation and proceeds to commit the update. The form does think it is a mandatory field as the blue asterisks appears, it just doesn't behave as such.

I can validate this is definitely the problem because if you edit raw value, change it to null, then try to submit, it spits out the expected cannot be null error.

I tried two field validation methods to sidestep this, and neither worked: Field is not empty: still saved Regex not match "[]": still saved

I also tried manually pushing a null back to the item via API, but the change wouldn't stick and keeps going back to []

As an aside, if i try to filter the collection using Files is empty, all items appear. If i use is not empty, all items still appear. If i do Count Files = 0 and >= 1, it behaves as expected. So a potential workaround to this would be the count function being available in the field validation.

To Reproduce

  1. Create Files interface, mandatory
  2. Create checkbox with condition that makes Files non-mandatory when set
  3. Save item
  4. Edit item and remove the checkbox value. The blue mandatory asterisks appears
  5. Submit the form, the update commits without spitting out a field error for your blank mandatory field.

Errors Shown

No response

What version of Directus are you using?

9.17.4

What version of Node.js are you using?

16.17.0

What database are you using?

Postgres

What browser are you using?

Chrome

How are you deploying Directus?

cloud

shipsides-sparknel avatar Sep 09 '22 15:09 shipsides-sparknel

I confirm this. And also would like to have the default icon accorded to the field's default value: As default value, we have true, false, NULL But whatever is chosen, the default icon shown in the form is the square with a minus inside.

Pachat avatar Sep 19 '22 08:09 Pachat