Skip to content

Resolve "Forms - Show field only when conditions are met"

This merge request introduces the ability in the form view to only show fields when certain conditions are met. These conditions are related to the values of the other fields. If you for example have two fields, field A and field B, and field B has the condition that it's only visible when the value of field A matches test. When a visitors looks at the form, he shouldn't see field B, but when he provides test as a value for field A, it should become visible.

How it works

  • The conditions are the same as the view filters.
  • It should only be possible to set conditions for the fields that are before the field.
  • When the conditions is related to an unknown field, for example because the condition field is not before the field, it should end up in an error state.
  • If the filter type isn't compatible with the field, it should end up in an error state.

Naive implementation

The changes are a naive web-frontend focused implementation. This means that there is no backend validation on provided data. If field A is meant to be hidden because the other values do not match the conditions, and a value for field A is provided, it will still be seen as valid and saved in the table. The web-frontend does hide the field if it doesn't match the conditions. The reason is because we currently don't have the ability on the backend to see if a provided dict matches certain conditions. If this results in lots of spammy or invalid data in the future, we could consider solving this.

Testing pointers

  • It should only be possible to choose fields that are before the field.
  • A link row select modal should not unselect the currently selected form field.
  • If the field doesn't match the conditions it should not be showed in the real form.
  • If a field is required and it also has conditions, it should not be required when the hidden. It should be required when it's visible.
  • The normal filters and row coloring should still work as expected.
  • Test whether it's possible to import and export via the export_group_applications management command.
  • Test if the conditions are disabled in read only mode.

Jul-17-2022_17-55-05

image

TODO

  • Deleting field scenario.
  • Converting field type scenario.
  • Don't close exit field option highlight when clicking select row modal is open.
  • Make labels translatable.
  • Check for performance improvements.
  • Add more tests to the update form view field options.
  • Test concurrency.
  • Import export.
  • Read only view.
  • Fix bug in form.
  • Final check of all code.

Merge Request Checklist

  • changelog.md has been updated if required
  • New/updated Premium features are separated correctly in the premium folder
  • The latest Chrome and Firefox have been used to test any new frontend features
  • Documentation has been updated
  • Quality Standards are met
  • Performance: tables are still fast with 100k+ rows, 100+ field tables
  • The redoc API pages have been updated for any REST API changes
  • Our custom API docs are updated for changes to endpoints accessed via api tokens
  • The UI/UX has been updated following UI Style Guide

Closes #815 (closed) #1078 (closed)

Edited by Bram Wiepjes

Merge request reports