bootstrap-autocomplete icon indicating copy to clipboard operation
bootstrap-autocomplete copied to clipboard

on change won't get triggered using 'set'

Open mvhirsch opened this issue 4 years ago • 2 comments

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):

  • OS: Fedora 33
  • Browser Firefox 85, Chrome 88
  • Version 2.3.7

mvhirsch avatar Feb 24 '21 10:02 mvhirsch

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

xcash avatar Feb 24 '21 10:02 xcash

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?

mvhirsch avatar Feb 24 '21 10:02 mvhirsch