Я пытаюсь создать форму проверки с помощью jQuery Form Validator (http://www.formvalidator.net/index.html). Я хочу выполнить проверку элементов type="radio"
. Если вы не выберете какую-либо опцию, появится сообщение Please select a option
.Это мой HTML код:
<form id="form">
<label class="form__box--label" for="radio">What type of prototype do you need?</label> <br>
<div>
<input id="basic" class="form__box--radio" type="radio" name="radio" value="Basic">
<label class="form__box--option" for="basic">
Basic
</label>
</div>
<div>
<input id="premium" class="form__box--radio" type="radio" name="radio" value="premium">
<label class="form__box--option" for="premium">
Premium
</label>
</div>
<input type="submit" class="sectionform__form--button" value="Get an estimation">
</form>
Объявление это JS код:
$(document).ready(function(){
$.validate({
modules: 'html5',
{
rules: {
radio:{ required:true }
},
messages:
{
radio:
{
required:"Please select a option<br/>"
}
},
errorPlacement: function(error, element)
{
if ( element.is(":radio") )
{
error.appendTo( element.parents('.sectionform__form--box') );
}
else
{ // This is the default behavior
error.insertAfter( element );
}
}
}
});
});