xcash / bootstrap-autocomplete

Bootstrap Autocomplete
MIT License
168 stars 72 forks source link

on change won't get triggered using 'set' #109

Open mvhirsch opened 3 years ago

mvhirsch commented 3 years ago

Describe the bug

The change event won't get triggered if using .autocomplete('set').

To Reproduce Steps to reproduce the behavior:

  const $test = $('form .js-select');
  $test.autoComplete({
    minLength: 3,
    resolver: 'custom',
    events: {search},
    resolverSettings: {requestThrottling: 300}
  });

  $test.on('change', () => console.log('value changed')); // never printed into console
  $test.autoComplete('set', {value: 0, text: 'foobar'});

Expected behavior Expected a change event programatically, too.

Desktop (please complete the following information):

xcash commented 3 years ago

Hi @mvhirsch can you provide an use case for this? Actually it's not triggered by design to avoid a possible infinite event loop.

mvhirsch commented 3 years ago

can you provide an use case for this?

Sure. I'm currently building a form, where a user selects a product (via autocomplete) - that's simple and working. I need to set it programmatically, because I'm optionally prefilling the form by using an ID provided via query parameters.

Simply: If there is an ID provided, prefill the select/autocomplete, if not, a user must select one. In both cases I need to update my HTML to preview a rendering (not related to that form, but based on that selected product).

Not triggering "change" on a "change"-event seems a bit odd to me. Any suggestions?