formio / formio.js

JavaScript powered Forms with JSON Form Builder
https://formio.github.io/formio.js
MIT License
1.83k stars 1.04k forks source link

Error in radio or selectboxes from URL due to missing metadata #5624

Open sjamaan opened 4 weeks ago

sjamaan commented 4 weeks ago

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.

VikkiAlenn commented 3 weeks ago

@sjamaan Thank you for brining this up. We were able to replicate the behavior and created a ticket FIO-8443 for dev review.

lane-formio commented 3 weeks ago

After review, we don't expect to resource a developer to investigate this in the near future but would be happy to review any contributions to resolve this behavior.

JeSuisAlrick commented 2 weeks ago

After review, we don't expect to resource a developer to investigate this in the near future but would be happy to review any contributions to resolve this behavior.

Hi @lane-formio,

Thanks for reviewing the issue. I saw the jsfiddle project that the OP provided, but that's not a practical workaround for my team.

Since this has been deemed low-priority, what is the official work-around for this issue if one is using React?