In this case Values 'a' and 'b' are the correct answer, which i would want to give a score of '1' for each of them.
I have tried the scripts below without any success
value =
(['a'].includes(data.q1) ? 1 : 0) +
(['b'].includes(data.q1) ? 1 : 0);
value =
(data.q1 === 'a' ? 1 : 0 )
+ (data.q1 === 'b' ? 1 : 0 );
Hi Tom,
I think I would start with questioning why a data-grid is being used for this scenario? as users add additional rows how can you determine if the "value" column is correct? perhaps a table component or columns is actually what you need?
The data-grid is really intended for when you need a dynamic number of rows.
Hi Tom,
I think I would start with questioning why a data-grid is being used for this scenario? as users add additional rows how can you determine if the "value" column is correct? perhaps a table component or columns is actually what you need?
The data-grid is really intended for when you need a dynamic number of rows.
Hey Erin, This isn't a data grid. It's a select box component. The JS works with radio component which allows only one option to be selected, but the select box component which allows multiple selections doesn't seem to like the JS
Thanks for the additional screen shot, that makes a lot of sense now!
Important:
I noticed that the value column of each option in your select box is not unique. To prevent issues, you should make sure this is unique for each option (see my example below). I would also recommend copying the values I use in the screen shot below so that the JavaScript provided below will need minimal changes.
Solution:
The response to a select box component is stored as an object so accessing the response to each checkbox is done using data.selectBoxName.option
syntax.
To calculate a score, you can use the following method:
Add a number component into your form.
In the calculated value property of the number component add the following JavaScript. Remember to adapt it to your specific scenario.
value = (data.selectboxes.option015 ? 1 : 0) + (data.selectboxes.option0075 ? 1 : 0)
Here's the end result: