What’s going on is when you just press “Send” only the message-body textbox is turning red, meaning errorClass: ‘errorField’ was applied to it like it should be, but the other elements do not turn red, like they should.
Also, the focus properly goes to the message-email text input, so perhaps errorClass is properly being applied to this field as well but then when you change the focus to the message-subject field the message-email field should turn red.
Finally, how do I have the errorField class override the focus class?
Thanks for your help!
HTML:
<head>
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script>
<script type="text/javascript" src="http://dev.jquery.com/view/trunk/plugins/validate/jquery.validate.js"></script>
<link rel="stylesheet" type="text/css" href="style/message.css">
<script type="text/javascript">
$(document).ready(function() {
$("#message-form").validate({
errorClass: 'errorField',
errorPlacement: function(error,element) {
return true;
}
});
});
</script>
</head>
<body>
blue = focus, green=notFocus, red=error
<div id="message-wrapper">
<form id="message-form" method="POST" action="">
<table>
<tr>
<td width="70px"><label for="message-email">From:</label></td>
<td><input type="text" name="message-email" id="message-email" class="message-input required email" /></td>
</tr>
<tr>
<td><label for="message-subject">Subject:</label> </td>
<td><input type="text" name="message-subject" id="message-subject" class="message-input required" minlength="5"/></td>
</tr>
<tr>
<td><label for="message-body" style="vertical-align: top">Message:</label> </td>
<td><textarea name="message-body" id="message-body" rows="4" cols="40" class="message-input required"></textarea></td>
</tr>
</table>
<input type="hidden" name="contact" value="1" />
<p><button type="submit">Send</button></p>
</form>
</div>
</body>
CSS:
div#message-wrapper{
width: 300px;
height: 400px;
}
input[type="text"], textarea {
/* background:#F4F4F4; */
background: green;
color: white;
border: solid 2px #DFDFDF;
}
input[type="text"]:focus, textarea:focus {
/* background:#F2F4F8; */
background: blue;
color: white;
border:solid 2px #333;
outline: 0;
}
.errorField{
/* background:#faf6d1; */
background: red;
color:black;
border:solid 1px #333;
}
.message-input{
width: 341px;
}
The selectors are the issue:
input[type="text"]is more specific than.message-input, so the background color does not changeinput.message-input:focusinstead ofinput[type="text"]:focusandinput.message-input.errorField:focusinstead of.errorField