LP1852782 Prevents data fields swapping to control fields
[working/Evergreen.git] / Open-ILS / src / eg2 / src / app / staff / share / marc-edit / marcrecord.ts
index 69e0955..cdc99aa 100644 (file)
@@ -19,6 +19,11 @@ export interface MarcField {
     ind2?: string;
     subfields?: MarcSubfield[];
 
+    // Fields are immutable when it comes to controlfield vs.
+    // data field.  Stamp the value when stamping field IDs.
+    isCtrlField: boolean;
+
+    // Pass-through to marcrecord.js
     isControlfield(): boolean;
 
     deleteExactSubfields(...subfield: MarcSubfield[]): number;
@@ -89,10 +94,15 @@ export class MarcRecord {
         this.fields.forEach(f => this.stampFieldId(f));
     }
 
+    // Stamp field IDs the the initial isCtrlField state.
     stampFieldId(field: MarcField) {
         if (!field.fieldId) {
             field.fieldId = Math.floor(Math.random() * 10000000);
         }
+
+        if (field.isCtrlField === undefined) {
+            field.isCtrlField = field.isControlfield();
+        }
     }
 
     field(spec: string, wantArray?: boolean): MarcField | MarcField[] {