Skip to content

Instantly share code, notes, and snippets.

@DinoChiesa
Created August 4, 2016 19:38
Show Gist options
  • Save DinoChiesa/41dd244409bce64766b765ca89672a65 to your computer and use it in GitHub Desktop.
Save DinoChiesa/41dd244409bce64766b765ca89672a65 to your computer and use it in GitHub Desktop.
// 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