Skip to content
Snippets Groups Projects
Commit ca1d1678 authored by Timothee P's avatar Timothee P :sunflower:
Browse files

fix error with list conditional field activation

parent 01dc7b45
No related branches found
No related tags found
No related merge requests found
import featureAPI from '@/services/feature-api'; import featureAPI from '@/services/feature-api';
import { isNil } from 'lodash';
export function formatStringDate(stringDate) { export function formatStringDate(stringDate) {
const date = new Date(stringDate); const date = new Date(stringDate);
if (date instanceof Date && !isNaN(date.valueOf())) { if (date instanceof Date && !isNaN(date.valueOf())) {
...@@ -202,12 +202,17 @@ export function isXtraFormActive(extraForms, config) { // return true if no conf ...@@ -202,12 +202,17 @@ export function isXtraFormActive(extraForms, config) { // return true if no conf
const { conditionField, conditionValue } = config; const { conditionField, conditionValue } = config;
// get the customForm which activates conditional field // get the customForm which activates conditional field
const conditioningXForm = extraForms.find((xForm) => xForm.name === conditionField); const conditioningXForm = extraForms.find((xForm) => xForm.name === conditionField);
// check if its value match the condition value // check if the conditioning extraform value match the condition value
if (conditioningXForm) { if (conditioningXForm) {
if (Array.isArray(conditionValue) && conditioningXForm.value) { // if the values to compare are null or undefined the field can't be activated
if (isNil(conditioningXForm.value) || isNil(conditionValue)) {
return false;
} else if (Array.isArray(conditionValue) && Array.isArray(conditioningXForm.value)) { // case of multiple list or prerecorded values list
return conditioningXForm.value.some((value) => conditionValue.includes(value)); return conditioningXForm.value.some((value) => conditionValue.includes(value));
} else if (typeof conditioningXForm.value === 'object' && conditioningXForm.value.label) { // case of simple list
return conditioningXForm.value.label === conditionValue.label;
} else { } else {
return conditioningXForm.value === conditionValue; return conditioningXForm.value === conditionValue; // more simple case of other fields
} }
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment