Commit ca124e66 authored by dmacfarlane's avatar dmacfarlane
Browse files

fix: labelKey issue

parent 11e77a0e
Loading
Loading
Loading
Loading
+28 −25
Original line number Diff line number Diff line
@@ -30,6 +30,28 @@ const KEY_2 = 50;
  }
})
export class MentionDirective {

  @Input() triggerChar: string = "@";

  @Input() set mention(items:any[]){
    this.items = items;
  }

  @Input() mentionSelect: (selection: string) => (string) = (selection: string) => selection;

  // option to specify the field in the objects to be used as the item label
  @Input() labelKey:string = 'label';

  // option to diable internal filtering. can be used to show the full list returned 
  // from an async operation (or allows a custom filter function to be used - in future)
  @Input() disableSearch:boolean = false;
  
  // option to limit the number of items shown in the pop-up menu
  @Input() maxItems:number = -1;

  // event emitted whenever the search term changes
  @Output() searchTerm = new EventEmitter();

  searchString: string;
  startPos: number;
  items: any[];
@@ -37,28 +59,24 @@ export class MentionDirective {
  searchList: MentionListComponent;
  stopSearch: boolean;
  iframe: any; // optional

  constructor(
    private _element: ElementRef,
    private _componentResolver: ComponentFactoryResolver,
    private _viewContainerRef: ViewContainerRef
  ) {}

  @Input() triggerChar: string = "@";

  @Input() set mention(items:any[]){
    if (items && items.length>0) {
      if (typeof items[0] == 'string') {
  ngOnInit() {
    if (this.items && this.items.length>0) {
      if (typeof this.items[0] == 'string') {
        // convert strings to objects
        const me = this;
        this.items = items.map(function(label){ 
        this.items = this.items.map(function(label){ 
          let object = {};
          object[me.labelKey] = label;
          return object;
        });
      }
      else {
        this.items = items;
      }
      // remove items without an objectKey (label)
      this.items = this.items.filter(e => e[this.labelKey]);
      this.items.sort((a,b)=>a[this.labelKey].localeCompare(b[this.labelKey]));
@@ -66,21 +84,6 @@ export class MentionDirective {
    }
  }  

  @Input() mentionSelect: (selection: string) => (string) = (selection: string) => selection;

  // option to specify the field in the objects to be used as the item label
  @Input() labelKey:string = 'label';

  // option to diable internal filtering. can be used to show the full list returned 
  // from an async operation (or allows a custom filter function to be used - in future)
  @Input() disableSearch:boolean = false;
  
  // option to limit the number of items shown in the pop-up menu
  @Input() maxItems:number = -1;

  // event emitted whenever the search term changes
  @Output() searchTerm = new EventEmitter();

  setIframe(iframe: HTMLIFrameElement) {
    this.iframe = iframe;
  }