import {ElementRef, Component, Input, Output, OnInit, OnDestroy,
- ViewChild, EventEmitter, AfterViewInit, Renderer2} from '@angular/core';
+ ViewChild, EventEmitter, AfterViewInit} from '@angular/core';
import {Subscription} from 'rxjs';
import {filter} from 'rxjs/operators';
import {MarcRecord, MarcField, MarcSubfield} from './marcrecord';
export class EditableContentComponent
implements OnInit, AfterViewInit, OnDestroy {
+ static idGen = 0;
+
@Input() context: MarcEditContext;
@Input() field: MarcField;
@Input() fieldType: MARC_EDITABLE_FIELD_TYPE = null;
get record(): MarcRecord { return this.context.record; }
bigText = false;
- randId = Math.floor(Math.random() * 100000);
+ randId = 'editable-content-' + EditableContentComponent.idGen++;
editInput: any; // <input/> or <div contenteditable/>
maxLength: number = null;
@ViewChild('insertAfter', {static: false}) insertAfterStr: StringComponent;
@ViewChild('deleteField', {static: false}) deleteFieldStr: StringComponent;
- constructor(private renderer: Renderer2) {}
-
tt(): TagTable { // for brevity
return this.context.tagTable;
}
}
ngAfterViewInit() {
- this.editInput = // numeric id requires [id=...] query selector
- this.renderer.selectRootElement(`[id='${this.randId}']`);
+ this.editInput = document.getElementById(this.randId + '');
// Initialize the editable div
this.editInput.innerText = this.getContent();