From c82d90d6451ea781ef7c24c4fa3b69754f3476da Mon Sep 17 00:00:00 2001 From: Erick Badilla Date: Thu, 28 Nov 2024 08:04:25 -0600 Subject: [PATCH] Added support for relate fields in update value backend actions --- .../update-value-backend.action.ts | 26 +++++++++++++++---- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/core/app/core/src/lib/fields/field-logic/update-value-backend/update-value-backend.action.ts b/core/app/core/src/lib/fields/field-logic/update-value-backend/update-value-backend.action.ts index ae946f15c1..d8636e0653 100644 --- a/core/app/core/src/lib/fields/field-logic/update-value-backend/update-value-backend.action.ts +++ b/core/app/core/src/lib/fields/field-logic/update-value-backend/update-value-backend.action.ts @@ -159,11 +159,27 @@ export class UpdateValueBackendAction extends FieldLogicActionHandler { * @param {string} value * @param {object} record */ - protected updateValue(field: Field, value: string, record: Record): void { - field.value = value.toString(); - field.formControl.setValue(value); + protected updateValue(field: Field, value: string, record: Record): void { + switch (field.type) { + case "relate": + const relateValue = JSON.parse(value); + + // Field that displays the related record + field.value = relateValue.id.toString(); + field.valueObject = {id: relateValue.id, name: relateValue.name}; + field.formControl.setValue({...field.valueObject}); + + // Field that stores the related record's ID + const relateFieldDB = record.fields[field.definition.id_name]; + relateFieldDB.value = field.value; + relateFieldDB.formControl.setValue(field.value); + + default: + field.value = value.toString(); + field.formControl.setValue(value); + } + // re-validate the parent form-control after value update record.formGroup.updateValueAndValidity({onlySelf: true, emitEvent: true}); } - -} +} \ No newline at end of file