Created
May 27, 2016 11:56
-
-
Save WietseWind/52dd30c40cd2732c03373b079270b957 to your computer and use it in GitHub Desktop.
Select2 "required"
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
$(".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