Comments in Calculated Value prevent the value being displayed
Describe the bug Our users have some calculated values in their Text Field component that do not display if a comment is made after the value is calculated.
For example, if a text field has the API property name set to A and a second text field uses a calculated value of value = data.A, the second field mirrors the input from the first. But if a comment is added value = data.A //comment, the text field remains blank.
I understand this is because the entire calculated value is evaluated as a string in the calculateValue property of the form's JSON, and adding a comment at the end does not return any value. Is that correct?
Is this a bug that can be fixed?
Version/Branch Sandbox (Default)
To Reproduce Steps to reproduce the behavior:
- Navigate to: https://formio.github.io/formio.js/app/sandbox.html
- Enter Sandbox id:
66da30361aeaa15811339869and Load Sandbox - Navigate to 'Form Rendered' at the bottom of the page
- Enter something in the 'Text Field (A)'
Expected behavior The value should be displayed in both text fields.
Screenshots
hi, formio is glueing 'return value' to the end of the script, so in your case that would be
//test comment return value
in that scenario return is a part of the comment so will be omitted by the evaluator
would be nice if formio team could fix that by glueing return to the new line, or maybe even by requiring return statement from users (makes sense especially when we're using if statements with early returns)
the fast workaround is just placing comments not on the last line of script
We have created a ticket for this. In the meantime, if you would like to submit a pull request, we would review it. Ticket for internal tracking: FIO-8803