diff --git a/core/app/core/src/lib/fields/base/base-field.component.ts b/core/app/core/src/lib/fields/base/base-field.component.ts index 08379ef1b..416e39bd7 100644 --- a/core/app/core/src/lib/fields/base/base-field.component.ts +++ b/core/app/core/src/lib/fields/base/base-field.component.ts @@ -146,17 +146,18 @@ export class BaseFieldComponent implements FieldComponentInterface, OnInit, OnDe if (this.field.valueChanges$ && ((this.dependentFields && Object.keys(this.dependentFields).length) || this.dependentAttributes.length)) { this.subs.push(this.field.valueChanges$.pipe(debounceTime(500)).subscribe((data) => { Object.keys(this.dependentFields).forEach(fieldKey => { - const dependentField = this.dependentFields[fieldKey]; + const dependentFieldKey = this.dependentFields[fieldKey]; const field = this.record.fields[fieldKey] || null; + const dependentField = this.record.fields[dependentFieldKey.field] || null; if (!field) { return; } if (this.field.previousValue != data.value) { - const types = dependentField.type ?? []; + const types = dependentFieldKey.type ?? []; if (types.includes('logic')) { - this.logic.runLogic(field, this.originalMode as ViewMode, this.record, 'onValueChange'); + this.logic.runLogic(field, this.originalMode as ViewMode, this.record, 'onDependencyChange', dependentField); } if (types.includes('displayLogic')) { diff --git a/core/app/core/src/lib/fields/field-logic/email-primary-select/email-primary-select.action.ts b/core/app/core/src/lib/fields/field-logic/email-primary-select/email-primary-select.action.ts index 21f3af98b..3ea1fc739 100644 --- a/core/app/core/src/lib/fields/field-logic/email-primary-select/email-primary-select.action.ts +++ b/core/app/core/src/lib/fields/field-logic/email-primary-select/email-primary-select.action.ts @@ -76,4 +76,9 @@ export class EmailPrimarySelectAction extends FieldLogicActionHandler { emailField.formControl.updateValueAndValidity({onlySelf: true, emitEvent: true}); } } + + getTriggeringStatus(): string[] { + return ['onFieldInitialize']; + } + } diff --git a/core/app/core/src/lib/fields/field-logic/field-logic.manager.ts b/core/app/core/src/lib/fields/field-logic/field-logic.manager.ts index db4be378d..ee98d98f7 100644 --- a/core/app/core/src/lib/fields/field-logic/field-logic.manager.ts +++ b/core/app/core/src/lib/fields/field-logic/field-logic.manager.ts @@ -84,15 +84,16 @@ export class FieldLogicManager extends BaseActionManager { * @param {object} mode * @param {object} record * @param triggeringStatus + * @param dependentField */ - runLogic(field: Field, mode: ViewMode, record: Record, triggeringStatus: string = ''): void { + runLogic(field: Field, mode: ViewMode, record: Record, triggeringStatus: string = '', dependentField: Field = {} as Field): void { if (!field.logic) { return; } const actions = Object.keys(field.logic).map(key => field.logic[key]); - const modeActions = this.parseModeActions(actions, mode, triggeringStatus); + const modeActions = this.parseModeActions(actions, mode, triggeringStatus, dependentField); const context = { record, field, @@ -147,7 +148,7 @@ export class FieldLogicManager extends BaseActionManager { * @param mode * @param triggeringStatus */ - protected parseModeActions(declaredActions: Action[], mode: ViewMode, triggeringStatus: string) { + protected parseModeActions(declaredActions: Action[], mode: ViewMode, triggeringStatus: string, fieldDependent: Field) { if (!declaredActions) { return []; } @@ -181,10 +182,21 @@ export class FieldLogicManager extends BaseActionManager { availableActions[mode].forEach(action => { - const frontendActionTriggeringStatus = this?.actions[mode][action.key]?.getTriggeringStatus() ?? null; - const actionTriggeringStatus = action?.triggeringStatus ?? frontendActionTriggeringStatus ?? defaultTriggeringStatus; + const dependentFieldsKeys = Object.keys(action?.params?.activeOnFields ?? {}); - if(triggeringStatus && !actionTriggeringStatus.includes(triggeringStatus)) { + const frontendActionTriggeringStatus = this?.actions[mode][action.key]?.getTriggeringStatus() ?? null; + + let actionTriggeringStatus = action?.triggeringStatus ?? frontendActionTriggeringStatus ?? defaultTriggeringStatus; + + if (triggeringStatus && !actionTriggeringStatus.includes(triggeringStatus)) { + return; + } + + if (actionTriggeringStatus.includes('onValueChange')) { + actionTriggeringStatus = ['onAnyLogic']; + } + + if (actionTriggeringStatus.includes('onDependencyChange') && !dependentFieldsKeys?.includes(fieldDependent.name)) { return; }