Skip to content

Instantly share code, notes, and snippets.

@salsalabs
Last active November 11, 2016 17:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save salsalabs/9abf8841ad1afe98e2bece8b42eacdac to your computer and use it in GitHub Desktop.
Save salsalabs/9abf8841ad1afe98e2bece8b42eacdac to your computer and use it in GitHub Desktop.
Script to correctly handle clicks on optional groups. An optional group needs to have a value in 'linkKey' no matter what. Salsa does not do this correctly and sometimes the wrong optional group is recorded. This script assures campaign managers that a clicked optional group either contains the groups_KEY or a zero.
<script type="text/javascript">
// Script to handle clicks on optional groups.
function optionalClick(event) {
var elem = event.target;
elem.value = elem.checked ? elem.getAttribute('alt-value') : 0;
}
// Find and configure all optional groups.
document.addEventListener("DOMContentLoaded", function() {
Array.from(document.querySelectorAll('input[id^="add_to_groups_KEY"]')).forEach(function(e) {
e.setAttribute('alt-value', e.getAttribute('value'));
e.addEventListener('change', optionalClick);
});
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment