Created
April 10, 2011 17:36
-
-
Save haacked/912552 to your computer and use it in GitHub Desktop.
Sample jQuery File
This file contains hidden or 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
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>Index</title> | |
<script src="../../Scripts/jquery-1.5.1.js" type="text/javascript"></script> | |
<script src="../../Scripts/jquery.validate.js" type="text/javascript"></script> | |
<script type="text/javascript"> | |
$(function () { | |
$("#form").validate({ | |
rules: { | |
accountType: "checked" | |
}, | |
messages: { | |
accountType: "You must select an account type" | |
} | |
}); | |
}); | |
</script> | |
</head> | |
<body> | |
<div> | |
<form id="form" method="post" action="/"> | |
<label>Select an Account Type</label> | |
<input type="text" name="foo" class="required" /> | |
<input type="radio" name="accountType" value="1" id="accountType_C" /><label for="accountType_C" >Coder</label> | |
<input type="radio" name="accountType" value="0" id="accountType_S" /><label for="accountType_S">Surreptitious Ninja</label> | |
<input type="submit" /> | |
</form> | |
</div> | |
</body> | |
</html> |
I haven't tested this but the jQuery documentation recommends the following:
Forms and their child elements should not use input names or ids that conflict with properties of a form, such as submit, length, or method. Name conflicts can cause confusing failures.
With that said, try changing the ID given to your form to something else.
Haacked,
$(function () {
$("#form").validate({
rules: {
accountType: {
required: true
}
}
});
});
or... u use:
jquery.metadata.js
$.metadata.setType("attr", "validate");
and finally a attribute validate in first radio of group:
(input type="radio" name="accountType" value="1" id="accountType_C" validate="required:true" /)
With message:
$(function () {
$("#form").validate({
rules: {
accountType: {
required: true
}
},
messages: {
accountType: 'You must select an account type'
}
});
});
Thanks all! I fixed it here: https://gist.github.com/912630
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I´m not quite sure, but you might try this: