From: Galen Charlton Date: Tue, 1 Sep 2020 02:39:49 +0000 (-0400) Subject: LP#1857150: eg-fm-record-editor: add isDirty() method X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=3b146dc53485d87740c357610be9d214dc1cdae2;p=evergreen%2Fmasslnc.git LP#1857150: eg-fm-record-editor: add isDirty() method This adds an isDirty() method to the form that components embedding an eg-fm-record-editor can use to check whether the form is currently dirty. NOTE: not all of the custom components that can show up on an fm-edit form currently implement component-level dirty checks. Sponsored-by: Evergreen Community Development Initiative Signed-off-by: Galen Charlton Signed-off-by: Ruth Frasur Signed-off-by: Bill Erickson Signed-off-by: Jason Etheridge --- 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 a396fd44ef..9a1a12efef 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 @@ -1,5 +1,6 @@ import {Component, OnInit, Input, ViewChild, Output, EventEmitter, TemplateRef} from '@angular/core'; +import {NgForm} from '@angular/forms'; import {IdlService, IdlObject} from '@eg/core/idl.service'; import {Observable} from 'rxjs'; import {map} from 'rxjs/operators'; @@ -158,6 +159,7 @@ export class FmRecordEditorComponent @ViewChild('successStr', { static: true }) successStr: StringComponent; @ViewChild('failStr', { static: true }) failStr: StringComponent; @ViewChild('confirmDel', { static: true }) confirmDel: ConfirmDialogComponent; + @ViewChild('fmEditForm', { static: false}) fmEditForm: NgForm; // IDL info for the the selected IDL class idlDef: any; @@ -293,6 +295,10 @@ export class FmRecordEditorComponent return this.displayMode === 'dialog'; } + isDirty(): boolean { + return this.fmEditForm ? this.fmEditForm.dirty : false; + } + // DEPRECATED: This is a duplicate of this.record = abc; setRecord(record: IdlObject) { console.warn('fm-editor:setRecord() is deprecated. ' + @@ -618,6 +624,9 @@ export class FmRecordEditorComponent this.pcrud[this.mode]([recToSave]).toPromise().then( result => { this.recordSaved.emit(result); + if (this.fmEditForm) { + this.fmEditForm.form.markAsPristine(); + } this.successStr.current().then(msg => this.toast.success(msg)); if (this.isDialog()) { this.record = undefined; this.close(result); } },