Skip to content

Commit

Permalink
Merge pull request #18900 from vlastikcz/v4-dev-buttonChange
Browse files Browse the repository at this point in the history
Button toggling - trigger change event on input. Fixes #16673, fixes #17599.
  • Loading branch information
mdo authored Nov 26, 2016
2 parents ce31f54 + 866e99b commit b6b8280
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion js/src/button.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ const Button = (($) => {

if (triggerChangeEvent) {
input.checked = !$(this._element).hasClass(ClassName.ACTIVE)
$(this._element).trigger('change')
$(input).trigger('change')
}

input.focus()
Expand Down
20 changes: 20 additions & 0 deletions js/tests/unit/button.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,26 @@ $(function () {
assert.strictEqual($btn.attr('aria-pressed'), 'true', 'btn aria-pressed state is true')
})

QUnit.test('should trigger input change event when toggled button has input field', function (assert) {
assert.expect(1)
var done = assert.async()

var groupHTML = '<div class="btn-group" data-toggle="buttons">'
+ '<label class="btn btn-primary">'
+ '<input type="radio" id="radio" autocomplete="off">Radio'
+ '</label>'
+ '</div>'
var $group = $(groupHTML).appendTo('#qunit-fixture')

$group.find('input').on('change', function (e) {
e.preventDefault()
assert.ok(true, 'change event fired')
done()
})

$group.find('label').trigger('click')
})

QUnit.test('should check for closest matching toggle', function (assert) {
assert.expect(12)
var groupHTML = '<div class="btn-group" data-toggle="buttons">'
Expand Down

0 comments on commit b6b8280

Please sign in to comment.