Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issues with sui-select properties #426

Open
LuisUgalde opened this issue Dec 13, 2018 · 0 comments
Open

Issues with sui-select properties #426

LuisUgalde opened this issue Dec 13, 2018 · 0 comments

Comments

@LuisUgalde
Copy link

Bug description

I'm having a problem with two specific properties of the sui-select component. These being, labelField and optionsFilter. I'm trying to use labelField to display the name property of my Category object, but when the dropdown menu shows the options they appear like this: [object Object]. And then I'm trying to use the optionsFilter to update the possible options by calling my back-end endpoints and filtering the results based on the query. Neither of these work for me and I'm just wandering if I'm not using them correctly and simply didn't understand the documentation. Anyway I would really appreciate some help with this, I'll try to post as much information as I can below.

I'm using the sui-select component as follows:

<form [formGroup]="createCategoryForm">
  <div class="form-group">
    <label class="col-md-2 control-label">{{'models.category.category' | translate}}</label>
      <div class="col-md-8">
        <sui-select 
          formControlName="category" 
          [options]="categories"
          [optionsFilter]="categoryFilter"
          [labelField]="name"
          [isSearchable]=true
          #select>
          <sui-select-option *ngFor="let option of select.filteredOptions" [value]="option">
          </sui-select-option>
      </sui-select>
    </div>
  </div>
</form

Options filter functions:

categoryFilter = (categories: Category[], query: string) => {
  if (query.trim()) {
    this.categoryService.getCategoriesFilteredByName(query).subscribe(data => {
      return data;
    });
  }
  else return false;
};

getCategoriesFilteredByName(name: string) {
  return this.http.get(`${this.apiUrl}categories?filters=name=${name}`,
    { headers: this.utilsService.createHeaders() }) as Observable<Category[]>;
}

The categories are an array in my component that's initialized in the ngOnInit method:

ngOnInit() {
  this.categoryService.getCategories().subscribe(data => {
    this.categories = data;
  });
}

I'm using reactive forms like so:

this.createCategoryForm = this.fb.group({
   category: [{}],
   values: [[]],
   visibleOnRegister: [false],
   requiredOnRegister: [false],
});

Also here's the category model:

export interface Category {
  id?: string;
  name?: string;
  paramName?: string;
}

Versions

Angular: 5.0.5
ng2-semantic-ui: 0.9.7

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant