opengovsg / checkfirst

Don't Know? CheckFirst. A tool to build eligibility checkers and calculators for Singapore Government policies
https://checkfirst.gov.sg
Other
12 stars 6 forks source link

fix: indexing for new radio or checkbox option #1058

Closed lamkeewei closed 3 years ago

lamkeewei commented 3 years ago

Problem

New options index was not referring to the react hook form field array. addOption should be referring to options instead of field.options, which is only updated after each save. Therefore, radio and checkbox options that have more than three options would not work as the index will always be 1 for all new option since field.options is still the same length.

To reproduce on production:

  1. Create a new check with 3 radio option
  2. Create a result that has returns the value of the radio question
  3. Select the third option
  4. Notice that when the third option is selected, the second option is also selected.

This only affect checkers that tried to add an option after the block validation feature as introduced.

Solution

Bug Fixes:

Tests