NIT-Administrative-Systems / dynamic-forms

Dynamic Forms for Laravel
https://nit-administrative-systems.github.io/dynamic-forms/
MIT License
39 stars 19 forks source link

allow non boolean simple conditionals #454

Closed mc0918 closed 6 months ago

mc0918 commented 6 months ago

Overview

Previously, the SimpleConditional logic only checked for an array key and its value, i.e.

[
  'when' => 'key',
  'equalTo' => 'value',
  'show' => true
]

for formio data like:

[
  'submissionValues' => [
    'key' => 'value'
  ]
]

However, SelectBoxes and Select with the multivalue option enabled format their values differently, leading to SimpleConditional::invoke() always returning false and the components' values being ignored during validations. An example in SOAP is, because the values of these ignored components are not persisted, missing PDF uploads: Screenshot (221)

This PR expands the SimpleConditional logic to cover these cases, handling the following:

// SelectBoxes tracks each selected option by setting the corresponding key to true
'submissionValues' => [
    'key' => [
        'option1' => true,
        'option2' => false,
    ],
],

and

// multivalue Select components track each selected option via an array of selected option keys
'submissionValues' => [
    'key' => [
        'option1', 'option2'
    ],
],

So now all the conditionals shown below just work(tm), and values will be persisted. aaaaaaa

Checklist

github-actions[bot] commented 6 months ago

Test Results

841 tests  +2   841 :white_check_mark: +2   34s :stopwatch: -2s 124 suites ±0     0 :zzz: ±0    1 files   ±0     0 :x: ±0 

Results for commit c7577a4f. ± Comparison against base commit 8bc15d83.

:recycle: This comment has been updated with latest results.

coveralls commented 6 months ago

Coverage Status

coverage: 95.532% (+0.02%) from 95.514% when pulling c7577a4fc8d3b7196e8f000f53f7322488402f73 on allow-select-box-conditionals into 8bc15d83f709921ba313e256ef63720ff2350ca5 on develop.