Sha256: 20d7f8b8e8012e1fd765ab2cc9d632bf67b192a0f9a29167c98fa98106398784
Contents?: true
Size: 1.5 KB
Versions: 6
Compression:
Stored size: 1.5 KB
Contents
// This component relies on JavaScript from GOV.UK Frontend //= require govuk-frontend/components/checkboxes/checkboxes.js window.GOVUK = window.GOVUK || {}; window.GOVUK.Modules = window.GOVUK.Modules || {}; (function (Modules) { 'use strict'; Modules.Checkboxes = function () { this.start = function (scope) { var _this = this; $(scope).find('[data-nested=true] input[type=checkbox]').on('change', function(e) { var checkbox = e.target; var isNested = $(checkbox).closest('.govuk-checkboxes--nested'); var hasNested = $('.govuk-checkboxes--nested[data-parent=' + checkbox.id + ']'); if (hasNested.length) { _this.toggleNestedCheckboxes(hasNested, checkbox); } else if (isNested.length) { _this.toggleParentCheckbox(isNested, checkbox); } }); }; this.toggleNestedCheckboxes = function(scope, checkbox) { if (checkbox.checked) { scope.find('input[type=checkbox]').prop("checked", true); } else { scope.find('input[type=checkbox]').prop("checked", false); } }; this.toggleParentCheckbox = function(scope, checkbox) { var siblings = $(checkbox).parent('.govuk-checkboxes__item').siblings(); var parent_id = scope.data('parent'); if (checkbox.checked && siblings.length == siblings.find(':checked').length) { $('#' + parent_id).prop("checked", true); } else { $('#' + parent_id).prop("checked", false); } }; }; })(window.GOVUK.Modules);
Version data entries
6 entries across 6 versions & 1 rubygems