-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to get the previous/old value on the "change"/"changed.bs.select" event? #1404
Comments
Actually, the following trick may work out: var previous_value;
$(".selectpicker").on('shown.bs.select', function(e) {
previous_value = $(this).val();
}).change(function() {
alert(previous_value);
previous_value = $(this).val();
}); |
Is there any solution for this yet? I tried @andrius-senulis suggestion above but it's not working for me. I also have multiple select boxes which are dynamically added to the page, and I need to be able to get the old and new values. I've also tried creating a JS function that would set the <select class="selectpicker" onfocus="setPreviousValue(this.value)">
<option>1</option>
</select> var previous;
function setPreviousValue(newValue) {
previous = newValue;
} The |
Update: So it looks like you can access the var previous;
$('.selectpicker').on('changed.bs.select', function (event, clickedIndex, newValue, oldValue) {
previous = oldValue;
}); For whatever reason this still isn't working for me, but that could be an issue on my part. Maybe this will help someone else though. |
Same situation here, I get only boolean values from |
Yes. I am also getting boolean values from |
Hi guys. Recently I've encountered the same problem and I solved it using "shown.bs.select" event:
Hope this helps! ;) |
Hi guys, As a note, the newValue and oldValues are supposed to return true/false, its the way they want it. If you like me and show/shown events dont fire (my reason is due to jquery and bootstrap being included more than once **dont ask me, company thing) I did the following to disable selected options and re-enable them should they not be selected anymore. You can also do something similar to remove and re-add properties. Great solution:
|
@andrius-senulis thanks!! it's working for me. |
Released in v1.13.0! @andrius-senulis Please feel free to close this issue. |
thank you |
Hello,
I have a problem getting the previous/old value of the select element on the change (or changed.bs.select) event. What would be the way to do it?
I don't want to use tricks like the following since I have many select elements in one page and I want to use the same event for all of them:
I have tried setting the data attribute with the old value to the select element but for some reason it does not get updated with the jQuery data() function.
Thank you,
Andrius
The text was updated successfully, but these errors were encountered: