AllenNeuralDynamics / aind-metadata-entry-js

Metadata entry using javascript
https://metadata-entry.allenneuraldynamics.org
MIT License
1 stars 1 forks source link

Validation shows false errors on entire subsections in select schemas #139

Closed helen-m-lin closed 6 months ago

helen-m-lin commented 6 months ago

Describe the bug When a user submits an incomplete form or a form with some errors, some schemas show errors on optional fields and other false positive errors.

To Reproduce Steps to reproduce the behavior:

  1. Go to https://metadata-entry.allenneuraldynamics-test.org/
  2. Select Rig in the "Select schema" dropdown
  3. [Optional] Fill out a few select fields, but making sure that some required fields are incomplete.
  4. Click the "Submit" button at the end of the form.
  5. Observe that in addition to expected validation errors on incomplete required fields, most other optional fields are also displaying validation errors (see screenshot 1 below)
  6. Resolve required fields (marked with *) in 1 sub-section only (e.g. enter Device name in Mouse Platform) while ignoring false positive errors on optional fields.
  7. Observe that the false positive errors for that subsection disappear.

Expected behavior There should not be false positive validation errors.

Screenshots

  1. False positive errors on optional fields: image

  2. After filling out required fields, false errors disappear: image

Desktop (please complete the following information):

Additional context We should check all schemas to see if the same issue is occurring. Rig seems to be experiencing the most issues.

jtyoung84 commented 6 months ago

We can try to pinpoint the underlying and timebox this to a few days at most

helen-m-lin commented 6 months ago

There were a few related issues causing validation errors:

  1. On default, the Ajv validator does not have discriminator support enabled. Each individual field was being compared against all possible oneOf options rather than only currently selected, causing multiple errors under each field.
  2. On default, Rjsf preserves previous form data after changing the selected option. This caused multiple must NOT have additional properties errors when the new option has a different schema and persisted incorrect values to the new schema.
  3. There was a bug in our preprocessing logic that added additionalProperties to empty arrays. This caused additional must NOT have additional properties errors.

These issues are addressed in PR #151