Created
August 4, 2016 19:38
-
-
Save DinoChiesa/41dd244409bce64766b765ca89672a65 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// toggle-chk.js | |
// ------------------------------------------------------------------ | |
// | |
// functions to toggle the checked state of checkboxes. | |
// | |
// The Drupal FAPI is too cumbersome to use for setting up | |
// mutually exclusive checkboxes. | |
// | |
// created: Wed Aug 3 15:53:33 2016 | |
// last saved: <2016-August-03 16:17:04> | |
(function ($){ | |
'use strict'; | |
var attrName = 'data-unset-if-checked'; | |
$(function() { | |
// for all checkbox that have this attr | |
$('div input['+attrName+'][type="checkbox"]').change(function () { | |
if (this.checked) { | |
var nameOfOtherElement = $(this).attr(attrName); | |
$('div input[name="'+ nameOfOtherElement +'"][type="checkbox"]').prop("checked", false); | |
} | |
}); | |
}); | |
}(jQuery)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment