formio.js
formio.js copied to clipboard
Error in radio or selectboxes from URL due to missing metadata
Describe the bug
When using the radio
or selectboxes
type with dataSrc: 'url'
, the setSubmission
function and associated setter crash when there is a missing metadata
property on submission.
It appears to be caused by inconsistencies across the code base regarding how metadata
is queried. For example, in radio.js, there's this code in setItem
, but in normalizeValue
when the isSelectUrl
getter returns true
, the same sort of code (where the crash happens) does not guard for missing a metadata
property - it simply assumes it to always be there.
In other places, like here, the lodash _.get
function is used with a path.
To make things worse, if the "right" combination of form elements are used, this error doesn't occur because some other function may have already set the metadata, so not all the buggy code will always trip over it.
Perhaps a simple way to fix this is to do the check in setSubmission
before calling any of the other functions? Then the guards can probably be removed everywhere, making for easier to read code. Alternatively, all the places where metadata
is used should be audited and fixed to ensure metadata
gets set when missing before attempting to read sub-properties of metadata
.
Version/Branch
4.19 (but also older versions, and 5.0 looks affected too)
To Reproduce
See this jsfiddle for an example: https://jsfiddle.net/dj7nv1rw/
If you click one of the select boxes, the input gets updated, but then it crashes (see console). If you click another box it won't update the input anymore. If you uncomment the line mentioned in the comment, it doesn't crash anymore. I consider this a workaround - according to the documentation, this should not be necessary.
Expected behavior
No crash when metadata
is missing from submission.