Skip to content

How to dynamically update options on type #28

@caseymct

Description

@caseymct

This is more of a question, and probably more related to selectize itself.

We are using ui-selectize to allow a user to add hashtags to a post. When the widget is initialized, I make a request to the server that populates the dropdown with trending hashtags. In Ember, I do this on

didInitAttrs() {
   this.fetchOptions();
}

where options is then passed in to tags-input:

{{tags-input
  options=options
  values=selectedTags
  placeholder=placeholder
  closeAfterSelect=true
  onChange=(action 'onChange')
  onLoad=(action 'onLoad')
  onType=(action 'onType')
  create=true
}}

in the onType action handler, as the user types, I want to issue an API request to the server that returns matching hashtags to their search, and dynamically update options; e.g.

actions: {
   onType(data) {
      let query = hashtags.asTag(data.value);

      if (!isEmpty(query)) {
         Ember.run.debounce(this, this.searchTags, query, this.DEBOUNCE_WAIT);
      }
      else if (!this.get('optionsEqualTrending')) {
        // If the user deletes their search, re-set options back to the initial list of trending tags
        this.setOptionsToTrending();
      }
  }

Where searchTags issues the api request and updates the options.
However, no matter what I do I can't seem to get the options to update. Ideally I'd like the dropdown to change while open to the matched tags. I've tried setting options directly, getting the selectize instance from the class (data.context.get('selectize');) and doing the following:

selectize.clearCache('option');
selectize.clearOptions();
selectize.addOption(options);
selectize.refreshOptions(true);

and nothing seems to update it. any help would be very appreciated.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions