From 9ce292c529de8a41b62b53cf039395c16744de05 Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Thu, 4 Feb 2021 16:42:20 -0500 Subject: [PATCH] LP1879517 FM editor field validator override example Signed-off-by: Bill Erickson --- .../src/app/share/fm-editor/fm-editor.component.html | 2 +- .../src/app/share/fm-editor/fm-editor.component.ts | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/Open-ILS/src/eg2/src/app/share/fm-editor/fm-editor.component.html b/Open-ILS/src/eg2/src/app/share/fm-editor/fm-editor.component.html index af9f5f0197..3919a2f7e6 100644 --- a/Open-ILS/src/eg2/src/app/share/fm-editor/fm-editor.component.html +++ b/Open-ILS/src/eg2/src/app/share/fm-editor/fm-editor.component.html @@ -203,7 +203,7 @@ diff --git a/Open-ILS/src/eg2/src/app/share/fm-editor/fm-editor.component.ts b/Open-ILS/src/eg2/src/app/share/fm-editor/fm-editor.component.ts index 4ac2e2eac9..1731b22914 100644 --- a/Open-ILS/src/eg2/src/app/share/fm-editor/fm-editor.component.ts +++ b/Open-ILS/src/eg2/src/app/share/fm-editor/fm-editor.component.ts @@ -73,6 +73,8 @@ export interface FmFieldOptions { // This supersedes all other isReadonly specifiers. isReadonlyOverride?: (field: string, record: IdlObject) => boolean; + isValidOverride: (field: string, record: IdlObject) => boolean; + // Render the field using this custom template instead of chosing // from the default set of form inputs. customTemplate?: CustomFieldTemplate; @@ -452,6 +454,23 @@ export class FmRecordEditorComponent }); } + fieldIsInvalid(): boolean { + + // todo: encapsulate this to avoid duplication w/ above. + const fields = this.idlDef.fields.filter(f => + !f.virtual && !this.hiddenFieldsList.includes(f.name)); + + let invalid = false; + fields.forEach(field => { + const fieldOptions = this.fieldOptions[field.name] || {}; + if (!fieldOptions.isValidOverride(field.name, this.record)) { + invalid = true; + } + }); + + return invalid; + } + private constructOneField(field: any): Promise { let promise = null; -- 2.11.0