Created
September 9, 2014 02:16
-
-
Save sahibalejandro/09e33c8d02eb3cd787d7 to your computer and use it in GitHub Desktop.
Enable/disable form controls based on status of other checkbox/radio controls
This file contains 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
/** | |
* "checkbox" style controls that enable/disable other controls | |
*/ | |
$('[data-controls-controller]').on('click', function (e) | |
{ | |
control_controller(this); | |
}) | |
.each(function () | |
{ | |
if (this.checked) { | |
control_controller(this); | |
} | |
}); | |
/** | |
* Enable/disable controls controlled by element. | |
* | |
* @param control | |
*/ | |
function control_controller(control) | |
{ | |
// Invert the disable/enable controls list based on the checked status of the control. | |
var controls_to_disable = $(control).data(control.checked ? 'disable-controls' : 'enable-controls'); | |
var controls_to_enable = $(control).data(control.checked ? 'enable-controls' : 'disable-controls'); | |
$(controls_to_disable).attr('disabled', 'disabled'); | |
$(controls_to_enable).removeAttr('disabled'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment