I have a radio button and added jQuery validation to make sure this radio button is checked. This works fine.
html:
<form id="myform">
<input type="radio" id="c1" name="cc" />
<label for="c1"><span></span>Check Box 1</label>
<input type="submit" />
</form>
javascript:
$(document).ready(function () {
$('#myform').validate({ // initialize the plugin
rules: {
'cc': {
required: true
}
},
messages: {
'cc': {
required: "You must check this"
}
},
submitHandler: function (form) {
alert('valid form submitted');
return false;
}
});
});
However if I add css to style the radio button, the validation doesn't work anymore. This is I guess, because the radiobutton is not displayed and thus the validation is removed from it. The question is of course, how can I fix this?
input[type="radio"] {
display:none;
}
input[type="radio"] + label span {
display:inline-block;
width:19px;
height:19px;
margin:-1px 4px 0 0;
vertical-align:middle;
background:url(https://cdn.tutsplus.com/webdesign/uploads/legacy/tuts/391_checkboxes/check_radio_sheet.png) -38px top no-repeat;
cursor:pointer;
}
input[type="radio"]:checked + label span {
background:url(https://cdn.tutsplus.com/webdesign/uploads/legacy/tuts/391_checkboxes/check_radio_sheet.png) -57px top no-repeat;
}