Select2 Required is not working


I have a modal window with three dropdowns. All these fields are specified as class=“required” in jsp. All these three are mandatory fields. When I try to save the modal window without entering value ,it thorws error as “Field Required” only for the first dropdown.
The other two drop down does not show the error message. Please advise.


Assuming you are using the browser’s built-in form validation, you need to set the required attribute on your <select> elements (for example, <select id="..." required>, not a class named ‘required’, which the browser does not understand.

If you could provide some sample code (on or showing how this is failing, I might be able to provide more guidance.


This is the jsp code

Item Details
Please choose the list flare
					<div class="input-field col s5">
						<select id="euomCd"  class="required">
							<option disabled selected>Please choose the list</option>
							</select> <label for="euomCd"><spring:message code="label.uom" /><i
							class="asterisk material-icons red-text darken-2">flare</i></label> 
						<input id="e_uom" type="hidden" name="eitUom" value=${editItemForm.eitUom}> 
					<div class="input-field col s4">
								<select id="ecriterion" class="required">
									<option disabled selected>Criterion</option>
									<option value="criterion"></option>										
								<label for="ecriterion"><spring:message code="label.criterion" /><i
							class="asterisk material-icons red-text darken-2">flare</i></label> 
								<input id="e_ocritCode" type="hidden"
									name="eitCriterion" value=${editItemForm.eitCriterion}>

After removing “class” (retaining “required”) and adding a name to each of the select components it works fine. Thank you for your help.


I’m glad my answer helped you. If you don’t mind, please give my answer a “Like” (click the heart icon). It helps my reputation on this site.