if (id) { this.recId = id; }
}
+ // Comma-separated list of field names defining the order in which
+ // fields should be rendered in the form. Any fields not represented
+ // will be rendered alphabetically by label after the named fields.
+ @Input() fieldOrder: string;
+
constructor(
private modal: NgbModal, // required for passing to parent
private idl: IdlService,
private getFieldList(): Promise<any> {
- this.fields = this.idlDef.fields.filter(f =>
- !f.virtual && !this.hiddenFieldsList.includes(f.name)
- );
+ const fields = this.idlDef.fields.filter(f =>
+ !f.virtual && !this.hiddenFieldsList.includes(f.name));
// Wait for all network calls to complete
return Promise.all(
- this.fields.map(field => this.constructOneField(field)));
+ fields.map(field => this.constructOneField(field))
+
+ ).then(() => {
+
+ if (!this.fieldOrder) {
+ this.fields = fields.sort((a, b) => a.label < b.label ? -1 : 1);
+ return;
+ }
+
+ let newList = [];
+ const ordered = this.fieldOrder.split(/,/);
+
+ ordered.forEach(name => {
+ const f1 = fields.filter(f2 => f2.name === name)[0];
+ if (f1) { newList.push(f1); }
+ });
+
+ // Sort remaining fields by label
+ const remainder = fields.filter(f => !ordered.includes(f.name));
+ remainder.sort((a, b) => a.label < b.label ? -1 : 1);
+ newList = newList.concat(remainder);
+
+ this.fields = newList;
+ });
}
private constructOneField(field: any): Promise<any> {
<!-- note: fieldOptions would be best defined in the .ts file, but
want to demostrate it can be set in the template as well -->
<eg-fm-record-editor #fmRecordEditor
- idlClass="cmrcfld" mode="create"
- [fieldOptions]="{marc_record_type:{customValues:[{id:'biblio'},{id:'serial'},{id:'authority'}]},description:{customTemplate:{template:descriptionTemplate,context:{'hello':'goodbye'}}}}"
- recordId="1" orgDefaultAllowed="owner">
+ idlClass="cmrcfld" mode="create" hiddenFields="id"
+ fieldOrder="owner,name,description,marc_format,marc_record_type,tag"
+ [fieldOptions]="{marc_record_type:{customValues:[{id:'biblio'},{id:'serial'},{id:'authority'}]},description:{customTemplate:{template:descriptionTemplate,context:{'hello':'goodbye'}}}}"
+ recordId="1" orgDefaultAllowed="owner">
</eg-fm-record-editor>
<button class="btn btn-dark" (click)="openEditor()">
Fm Record Editor