LP1879517 FM editor field validator override example user/berick/lp1879517-editor-valid-override-exampe
authorBill Erickson <berickxx@gmail.com>
Thu, 4 Feb 2021 21:42:20 +0000 (16:42 -0500)
committerBill Erickson <berickxx@gmail.com>
Thu, 4 Feb 2021 21:42:20 +0000 (16:42 -0500)
Signed-off-by: Bill Erickson <berickxx@gmail.com>
Open-ILS/src/eg2/src/app/share/fm-editor/fm-editor.component.html
Open-ILS/src/eg2/src/app/share/fm-editor/fm-editor.component.ts

index af9f5f0..3919a2f 100644 (file)
     </ng-container>
 
     <button type="button" class="btn btn-info" 
-      [disabled]="fmEditForm.invalid" *ngIf="mode != 'view'"
+      [disabled]="fmEditForm.invalid || fieldIsInvalid()" *ngIf="mode != 'view'"
       (click)="save()" i18n>Save</button>
   </div>
 </ng-template>
index 4ac2e2e..1731b22 100644 (file)
@@ -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<any> {
 
         let promise = null;