mirror of
https://github.com/twbs/bootstrap.git
synced 2025-08-13 17:14:04 +02:00
Merge pull request #11376 from twbs/double-click-radio-fix
Double-clicking on a .btn-ized radio button shouldn't de-select it
This commit is contained in:
14
dist/js/bootstrap.js
vendored
14
dist/js/bootstrap.js
vendored
@@ -220,15 +220,21 @@ if (typeof jQuery === "undefined") { throw new Error("Bootstrap requires jQuery"
|
|||||||
|
|
||||||
Button.prototype.toggle = function () {
|
Button.prototype.toggle = function () {
|
||||||
var $parent = this.$element.closest('[data-toggle="buttons"]')
|
var $parent = this.$element.closest('[data-toggle="buttons"]')
|
||||||
|
var changed = true
|
||||||
|
|
||||||
if ($parent.length) {
|
if ($parent.length) {
|
||||||
var $input = this.$element.find('input')
|
var $input = this.$element.find('input')
|
||||||
.prop('checked', !this.$element.hasClass('active'))
|
if ($input.prop('type') === 'radio') {
|
||||||
.trigger('change')
|
// see if clicking on current one
|
||||||
if ($input.prop('type') === 'radio') $parent.find('.active').removeClass('active')
|
if ($input.prop('checked') && this.$element.hasClass('active'))
|
||||||
|
changed = false
|
||||||
|
else
|
||||||
|
$parent.find('.active').removeClass('active')
|
||||||
|
}
|
||||||
|
if (changed) $input.prop('checked', !this.$element.hasClass('active')).trigger('change')
|
||||||
}
|
}
|
||||||
|
|
||||||
this.$element.toggleClass('active')
|
if (changed) this.$element.toggleClass('active')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
2
dist/js/bootstrap.min.js
vendored
2
dist/js/bootstrap.min.js
vendored
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
14
js/button.js
14
js/button.js
@@ -54,15 +54,21 @@
|
|||||||
|
|
||||||
Button.prototype.toggle = function () {
|
Button.prototype.toggle = function () {
|
||||||
var $parent = this.$element.closest('[data-toggle="buttons"]')
|
var $parent = this.$element.closest('[data-toggle="buttons"]')
|
||||||
|
var changed = true
|
||||||
|
|
||||||
if ($parent.length) {
|
if ($parent.length) {
|
||||||
var $input = this.$element.find('input')
|
var $input = this.$element.find('input')
|
||||||
.prop('checked', !this.$element.hasClass('active'))
|
if ($input.prop('type') === 'radio') {
|
||||||
.trigger('change')
|
// see if clicking on current one
|
||||||
if ($input.prop('type') === 'radio') $parent.find('.active').removeClass('active')
|
if ($input.prop('checked') && this.$element.hasClass('active'))
|
||||||
|
changed = false
|
||||||
|
else
|
||||||
|
$parent.find('.active').removeClass('active')
|
||||||
|
}
|
||||||
|
if (changed) $input.prop('checked', !this.$element.hasClass('active')).trigger('change')
|
||||||
}
|
}
|
||||||
|
|
||||||
this.$element.toggleClass('active')
|
if (changed) this.$element.toggleClass('active')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -111,6 +111,12 @@ $(function () {
|
|||||||
ok(!btn1.find('input').prop('checked'), 'btn1 is checked')
|
ok(!btn1.find('input').prop('checked'), 'btn1 is checked')
|
||||||
ok(btn2.hasClass('active'), 'btn2 has active class')
|
ok(btn2.hasClass('active'), 'btn2 has active class')
|
||||||
ok(btn2.find('input').prop('checked'), 'btn2 is checked')
|
ok(btn2.find('input').prop('checked'), 'btn2 is checked')
|
||||||
|
|
||||||
|
btn2.find('input').click() /* clicking an already checked radio should not un-check it */
|
||||||
|
ok(!btn1.hasClass('active'), 'btn1 does not have active class')
|
||||||
|
ok(!btn1.find('input').prop('checked'), 'btn1 is checked')
|
||||||
|
ok(btn2.hasClass('active'), 'btn2 has active class')
|
||||||
|
ok(btn2.find('input').prop('checked'), 'btn2 is checked')
|
||||||
})
|
})
|
||||||
|
|
||||||
})
|
})
|
||||||
|
Reference in New Issue
Block a user