allow for the explicit setting of null for certain eligible fields in fmEditor
authorJason Etheridge <jason@EquinoxOLI.org>
Fri, 16 Dec 2022 12:00:28 +0000 (07:00 -0500)
committerJason Etheridge <jason@EquinoxOLI.org>
Fri, 16 Dec 2022 12:06:16 +0000 (07:06 -0500)
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 518125c..08d2f74 100644 (file)
@@ -31,6 +31,9 @@
         <div class="col-lg-3">
           <label for="{{idPrefix}}-{{field.name}}">{{field.label}}</label>
           <eg-help-popover [placement]="'right'" *ngIf="field.helpText" helpText="{{field.helpTextValue}}"></eg-help-popover>
+          <ng-container *ngIf="isSafeToNull(field)">
+            <br />(<a (click)="setToNull(field)" href='javascript:;'><span i18n>Unset</span></a>)
+          </ng-container>
         </div>
         <div class="col-lg-9">
 
index 8c1f5ba..504539a 100644 (file)
@@ -421,9 +421,10 @@ export class FmRecordEditorComponent
             if (field.datatype === 'bool') {
                 if (rec[field.name]() === true) {
                     rec[field.name]('t');
-                // } else if (rec[field.name]() === false) {
-                } else { // TODO: some bools can be NULL
+                } else if (rec[field.name]() === false) {
                     rec[field.name]('f');
+                } else {
+                    rec[field.name](null);
                 }
             } else if (field.datatype === 'org_unit') {
                 const org = rec[field.name]();
@@ -715,6 +716,23 @@ export class FmRecordEditorComponent
             }
         );
     }
+
+    isSafeToNull(field) {
+        if (field.datatype == 'id') {
+            return false;
+        }
+        if (field.readOnly) {
+            return false;
+        }
+        if (field.isRequired()) {
+            return false;
+        }
+        return true;
+    }
+
+    setToNull(field) {
+        this.record[field.name](null);
+    }
 }
 
 // https://stackoverflow.com/a/57812865