formio.js icon indicating copy to clipboard operation
formio.js copied to clipboard

Comments in Calculated Value prevent the value being displayed

Open vijaivir opened this issue 1 year ago • 2 comments

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:

  1. Navigate to: https://formio.github.io/formio.js/app/sandbox.html
  2. Enter Sandbox id: 66da30361aeaa15811339869 and Load Sandbox
  3. Navigate to 'Form Rendered' at the bottom of the page
  4. Enter something in the 'Text Field (A)'

Expected behavior The value should be displayed in both text fields.

Screenshots

Screenshot 2024-09-05 at 3 42 32 PM

vijaivir avatar Sep 05 '24 22:09 vijaivir

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

jgrott avatar Sep 10 '24 10:09 jgrott

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

daneformio avatar Sep 18 '24 13:09 daneformio