Select2 and HTML5 form validation

Nizar picture Nizar · Sep 23, 2013 · Viewed 19.2k times · Source

How I can do a form validation (HTML5 Required) with Select2?

Answer

zizoujab picture zizoujab · May 16, 2015

This may be a late answer but anyway : you just add a required to the select and the html5 validation will show up :

Fiddle : http://jsfiddle.net/mksshhwt/

<form>
required select2: <select class="select2" required multiple name="test">
    <option>Test</option>
    <option>Test2</option>
</select>
    <br/>

    required select2: <select class="select2" required  name="test">
    <option>Test</option>
    <option>Test2</option>
</select>

    <br/>
<input type="submit" value="Test" />
</form>

JS :

$(".select2").select2();

you may get the validation a little on the top , follow this thread to fix it : https://github.com/select2/select2/issues/128