Ajax-Bootstrap-Select icon indicating copy to clipboard operation
Ajax-Bootstrap-Select copied to clipboard

with-ajax makes changed.bs.select event to be called on search, not on change

Open ppazos opened this issue 4 years ago • 10 comments

We have a select picker with ajax, and a changed.bs.select event registered to check when the select value changes. Without ajax, the event is triggered only when the new value is selected, but with ajax the event is triggered when the search result is displayed, not when a new value is selected.

It seems the AJAX complete is calling a refresh(true)

https://github.com/truckingsim/Ajax-Bootstrap-Select/blob/master/src/js/classes/AjaxBootstrapSelectRequest.js#L110

And the refresh(true) is triggering the change event

https://github.com/truckingsim/Ajax-Bootstrap-Select/blob/master/src/js/classes/AjaxBootstrapSelectList.js#L243-L245

I don't think that is the correct behavior, since the change should only be triggered when the user actually selects a new value, not when the options are updated.

ppazos avatar Mar 24 '20 18:03 ppazos

I've also encountered the behaviour stated in the main comment.

Martijn-Bos avatar Apr 28 '20 10:04 Martijn-Bos

Experiencing same here...

engin-can avatar May 03 '20 21:05 engin-can

@ppazos - Any idea how to detect deselection of options? I am able to detect option changes, but not deselection with changed.bs.select. It doesn't get triggered when there are no results found.

engin-can avatar May 04 '20 05:05 engin-can

Please take a look at this: https://stackoverflow.com/questions/61586202/how-to-catch-no-results-event-in-order-to-disable-input-field-in-bootstrap-sel

engin-can avatar May 04 '20 06:05 engin-can

@fbengo deselection is not related with this issue, this is about the search triggering a change event, but I guess for what you want you need to look for it in the code as I did to find the source of the issue I reported.

ppazos avatar May 04 '20 17:05 ppazos

I actually think it is related. I noticed that changed.bs.select is triggered when results for search query were found, and when an result option is selected. It is not triggered when no results were found. This behavior doesn't make sense to me. I tried to enable a different input field when an option is selected and disable it when no option is selected. I can't find a way to do this, because of this weird behavior...

screenshot

engin-can avatar May 05 '20 00:05 engin-can

As mentioned before, the bug is the event to be triggered when a search is done, that shouldn't happen. That is the only weird behavior. Then what you want to do is not related with the issue, could be a feature request though.

We actually face the issue you are having, what should be done is to remove the event call from the search code (link provided above).

ppazos avatar May 05 '20 11:05 ppazos

I don't completely agree. It is not always triggered after search. That's my problem with it. It is only triggered when results were found, not when no results were found.

engin-can avatar May 06 '20 00:05 engin-can

@engin-can I agree, it's change is always triggered on search when there are result. Either way, is something that shouldn't happen since the change event should be triggered when the user changes the select picker, not when the search is executed and got results.

ppazos avatar Oct 13 '20 20:10 ppazos

BTW Bootstrap-Select released a new version with AJAX support, I guess this AJAX plugin is not longer needed.

ppazos avatar Apr 02 '21 22:04 ppazos