Created
May 11, 2020 09:44
-
-
Save FabianSchmick/df1b890ad03dfb307b52155e15973d2a to your computer and use it in GitHub Desktop.
Reset radio - switch buttons
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
/** | |
* Initializes switch fields | |
* | |
* https://stackoverflow.com/a/8318129/5947371 | |
*/ | |
initSwitch() { | |
let selector = '.custom-control-input[type="radio"]'; | |
$(selector).each((index, radio) => { | |
let $radio = $(radio), | |
$label = $('label[for="'+radio.id+'"]'); | |
$label.add(radio).mousedown(function () { | |
$radio.data('checked', radio.checked); | |
}); | |
$label.add(radio).click(function () { | |
if ($radio.data('checked')) { | |
$radio.prop('checked', false); | |
} | |
}); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment