Skip to content

Commit

Permalink
Merge pull request #770 from alphagov/use-delegated-event-handler-che…
Browse files Browse the repository at this point in the history
…ckboxes

Use delegated event handlers for checkboxes
  • Loading branch information
36degrees authored Feb 26, 2019
2 parents 00c81f7 + 48483e5 commit 9ff2a25
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
## 16.1.0

* Enable ability to add data attributes to a single radio button (PR #766)
* Use delegated event handlers for checkbox events (PR #770)

## 16.0.0

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ window.GOVUK.Modules = window.GOVUK.Modules || {};
var _this = this;
this.applyAriaControlsAttributes(scope);

$(scope).find('[data-nested=true] input[type=checkbox]').on('change', function(e) {
$(scope).on('change', '[data-nested=true] input[type=checkbox]', function(e) {
var checkbox = e.target;
var isNested = $(checkbox).closest('.govuk-checkboxes--nested');
var hasNested = $('.govuk-checkboxes--nested[data-parent=' + checkbox.id + ']');
Expand All @@ -23,7 +23,7 @@ window.GOVUK.Modules = window.GOVUK.Modules || {};
}
});

$(scope).find('input[type=checkbox]').on('change', function(e) {
$(scope).on('change', 'input[type=checkbox]', function(e) {
if (GOVUK.analytics && GOVUK.analytics.trackEvent) {
var $checkbox = $(e.target);
var category = $checkbox.data("track-category");
Expand Down

0 comments on commit 9ff2a25

Please sign in to comment.