Skip to content

Instantly share code, notes, and snippets.

@ataraxie
Created February 9, 2018 20:27
Show Gist options
  • Save ataraxie/23009678d8076407b6c9196c36f7cb0c to your computer and use it in GitHub Desktop.
Save ataraxie/23009678d8076407b6c9196c36f7cb0c to your computer and use it in GitHub Desktop.
$formContainer
.on('change', 'select', function() {
let $select = $(this);
let selectedId = $select.val();
$select.find('option[value="'+selectedId+'"]').attr('selected', 'selected').siblings().removeAttr('selected');
})
.on('keyup', 'input[type="text"]', function() {
let $input = $(this);
let value = $input.val();
if (value) {
$input.attr('value', value);
} else {
$input.removeAttr('value');
}
})
.on('change', 'input:checkbox', function() {
$(this).attr('checked', 'checked');
})
.on('change', 'input:radio', function() {
let $input = $(this);
$input.closest('.control-group').find('input:radio').removeAttr('checked');
$input.attr('checked', 'checked');
})
;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment