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

adapt conditional field forms to simpler object

parent 5343a7e9
No related branches found
No related tags found
1 merge request!607REDMINE_ISSUE-17628 | Forcer la valeur d'un champ selon une condition
......@@ -430,7 +430,7 @@ export default {
checkDeactivatedValues() {
// if changes occured, update extra_forms array with freshly checked active customForms
let newExtraForms = this.extra_forms.map((xForm) => { // we use 'deactivate' instead of 'activate' because at initialization this property cannot be evaluated ...
const isDeactivated = !isXtraFormActive(this.extra_forms, xForm); // ... if the component is not created to set this property, thus no extra form would appear at all
const isDeactivated = !isXtraFormActive(this.extra_forms, xForm.conditional_field_config); // ... if the component is not created to set this property, thus no extra form would appear at all
// toggle value to null to deactivate other fields conditioned by it
if (isDeactivated) {
xForm['value'] = null;
......
......@@ -128,17 +128,13 @@ export function findCurrentValue(feature, customField) {
}
}
export function isXtraFormActive(extraForms, custField) { // return true if no config or if the condition is fullfilled
if (custField.conditional_field_config) { // if conditional field configuration is no null
const config = Object.entries(custField.conditional_field_config);
if (config[0]) { // if config contains entries (should be like this anyway, just to prevent errors)
const [conditionFieldName, conditionFieldValue] = config[0]; // get name and value in condition
// get the customForm which activates conditional field
const conditioningXForm = extraForms.find((xForm) => xForm.name === conditionFieldName);
// check if its value match the condition value
if (conditioningXForm) { // use JSON.stringify() to compare arrays (works with other field type too)
return JSON.stringify(conditioningXForm.value) === JSON.stringify(conditionFieldValue);
}
export function isXtraFormActive(extraForms, config) { // return true if no config or if the condition is fullfilled
if (config) { // if conditional field configuration is not null
// get the customForm which activates conditional field
const conditioningXForm = extraForms.find((xForm) => xForm.name === config.conditionField);
// check if its value match the condition value
if (conditioningXForm) { // use JSON.stringify() to compare arrays (works with other field type too)
return JSON.stringify(conditioningXForm.value) === JSON.stringify(config.conditionValue);
}
}
return true;
......
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