lekoala / bootstrap5-autocomplete

Autocomplete for Bootstrap 5 (and 4!)
MIT License
87 stars 16 forks source link

Feature: liveServer option should be reactive #24

Closed guifsdev closed 1 year ago

guifsdev commented 1 year ago

Hi, I'm having one more issue:

Updating liveServer via dataLiveServer option has no effect even when re-instantiating the object. For context, I'm using this when the component is mounted and/or dataLiveServer prop changes:

init() {
      if (!this.id) {
        console.error("AucompleteInput requires an id attribute.");
        return;
      }

      const opts = {
        onSelectItem: this.onSelectItem,
        fullWidth: true,
        suggestionsThreshold: 2,
        liveServer: this.dataLiveServer
      };

      const element = document.getElementById(this.id);

      const obj = new Autocomplete(element, opts);

      if (this.dataLiveServer) {
        console.log('should suggest!');
      }
      else {
        console.log('should not suggest!');
      }
      console.log('element: ', element);
      console.log('object: ', obj);
      console.log('options: ', opts)
    },

Component will remain completing or not completing results based on the initial state of liveServer option. I guess all options should be reactive.

lekoala commented 1 year ago

@guifsdev if you create a new instance, it should work well. i'm not sure what you mean by "re instantiating" ? data attributes are only read when creating the instance. if you change them, simply dispose/create it and you should be fine.

lekoala commented 1 year ago

or use setConfig in the current way it's built, data attributes are not meant to be reactive. Maybe something nice for a future version or a custom element or something ;-)