I want to use jQUery.validate in a MVC4 project. I have a wizard setup (from stepy) where I have 6 steps to go through. On each step I want to add validation. Now the validation works until appearantly I use a checkbox.
On step 2 I have a checkbox. When I then want to continue to step 3 it gives me the error:
Cannot read property name of undefined.
When I remove the checkbox all works fine. Also when I run the HTML it works but if I put it into MVC razor it fails.
Any help is appreciated.
thanks
This is the HTML + jQuery:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta http-equiv="Pragma" content="no-cache">
<meta http-equiv="Expires" content="-1">
<title>jQuery Stepy - A Wizard Plugin</title>
<link type="text/css" rel="stylesheet" href="css/jquery.stepy.css" />
<script type="text/javascript" src="js/jquery-1.8.2.js"></script>
<script type="text/javascript" src="js/jquery.validate.min.js"></script>
<script type="text/javascript" src="js/jquery.stepy.min.js"></script>
<script type="text/javascript">
$(function() {
$('#custom').stepy({
backLabel: 'Backward',
block: true,
errorImage: true,
nextLabel: 'Forward',
titleClick: true,
validate: true
});
// Optionaly
$('#custom').validate({
rules: {
'checked': 'required',
}, messages: {
'checked': { required: 'error' },
}
});
});
</script>
</head>
<body>
<div id="header">
</div>
<div id="content">
<form id="custom">
<fieldset title="Thread 1">
<legend>description one</legend>
<label>User:</label>
<!-- Hidden fields are not focused. -->
<input type="hidden" name="hidden" />
<!-- Disabled fields are not validated. -->
<input type="text" value="wbotelhos" size="40" name="user" disabled="disabled" />
<label>E-mail:</label>
<input type="text" size="40" name="email" />
<input type="checkbox" name="checked" /> Checked?
<label>Naa:</label>
<input type="text" size="40" name="Naam" />
<label>Newsletter?</label>
<input type="radio" name="newsletter" /> Yep
<input type="radio" name="newsletter" /> Nop
<label>Password:</label>
<input type="password" name="password" size="40" />
</fieldset>
<fieldset title="Thread 2">
<legend>description two</legend>
<label>Nick Name:</label>
<input type="text" size="30" />
<label>Bio:</label>
<textarea name="bio" rows="5" cols="60"></textarea>
</fieldset>
<fieldset title="Thread 3">
<legend>description three</legend>
<label>Birthday:</label>
<select name="day">
<option></option>
<option>23</option>
</select>
<select>
<option>10</option>
</select>
<select>
<option>1984</option>
</select>
<label>Site:</label>
<input type="text" name="site" size="40" />
</fieldset>
<input type="submit" class="finish" value="Finish!" />
</form><br/>
</body>
The code in the question is missing a closing div tag.
Other than that it there is no problem with it. The question is an example from stepy on github which does seem to work with check boxes. I would try to get the examples working correctly and check that you are referencing all the js files.