Skip to content

Instantly share code, notes, and snippets.

@WietseWind
Created May 27, 2016 11:56
Show Gist options
  • Save WietseWind/52dd30c40cd2732c03373b079270b957 to your computer and use it in GitHub Desktop.
Save WietseWind/52dd30c40cd2732c03373b079270b957 to your computer and use it in GitHub Desktop.
Select2 "required"
$(".searchselect").each(function(){
if($(this).attr('required')){
$(this).before(
'<input required="required" class="'+$(this).attr('class')+' fake-field" tabindex="-1" type="text" name="'+$(this).attr('name')+'" id="'+$(this).attr('id')+'" />'
);
$(this).attr('d-name', $(this).attr('name'));
$(this).removeAttr('name');
}
$(this).select2().on('change', function(){
if($(this).attr('d-name')){
$("input[name='"+$(this).attr('d-name')+"']").val($(this).val());
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment