molgenis
molgenis copied to clipboard
Fields with visible expression having the indexOf function are always shown when inserting via data explorer
How to Reproduce
Entity with different attributes. One or more attributes are always shown when doing data row editing using the forms edit plugin regardless of the value of one of the other attributes when the visible expression of this attribute includes the indexOf function.
Expected behavior
Attributes are not shown in the edit form unless the criterium is met to show this attribute (based on the inserted value of another attribute).
Observed behavior
Fields are always shown when the visible expression contains the indexOf function. This does not happen when data row editing is done when the forms edit plugin is turned off (so using the old form).
When the expression being evaluated generates an error the vue forms ( new forms ) stop evaluating the expression and in case of a isVisible defaults to being visible
https://github.com/molgenis/molgenis-ui-form/blob/e9b6cc5320bb96eb9007f485b04c4eb2a863fbe1/test/unit/specs/util/helpers/expressionEvaluators.spec.js#L32
The react forms ( old forms ) wrap the isVisible expression in a try catch block and default to false on error
https://github.com/molgenis/molgenis-frontend/blob/89440088c6df1522f683102067dde14bb8135fdf/packages/core-ui/src/modules/react-components/Form.js#L734
Proper solution imo would be to not rely on errors for control flow but to update the expression to include null checks where appropriate. Could however change the behaviour of the isVisible error handler in the vue form to catch the error and return false ( to match the react forms behaviour).
Indeed, error should be shown.
ok, so the fix is: keep the logic as is (visible on error) but show the error message. That is the change for this issue ticket. (Additionally, in this chr6 case: fix the null handling in the visible expressions.)
We ran into this for the old forms and decided then not to bother the user who is entering data if a metadata expression is incorrect. But to console.log errors to help with debugging.