truckingsim / Ajax-Bootstrap-Select

This uses the bootstrap-select plugin and extends it so that you can use a remote source to search.
MIT License
280 stars 97 forks source link

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

Open ppazos opened 4 years ago

ppazos commented 4 years ago

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.

Martijn-Bos commented 4 years ago

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

engin-can commented 4 years ago

Experiencing same here...

engin-can commented 4 years ago

@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 commented 4 years ago

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

ppazos commented 4 years ago

@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.

engin-can commented 4 years ago

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

ppazos commented 4 years ago

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

engin-can commented 4 years ago

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.

ppazos commented 3 years ago

@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 commented 3 years ago

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