Reputation: 3912
I'm pretty new to jQuery mobile, I'm using jQuery Validate plugin for forms control validation, everything working fine, but the validation message shows along with the input text box. Here is the image:
Jquery
$(document).live('pageinit', function (e) {
$('#form1').validate({
submitHandler: function (form) {
$.mobile.changePage('#success', { transition: "slide" });
return false;
}
});
});
HTML
<div data-role="fieldcontainer">
<label for="fname" data-theme="d">First Name:</label>
<input type="text" id="fname" name="fname" data-theme="d" placeholder="Enter First Name" required>
<br />
</div>
<div data-role="fieldcontainer">
<label for="lname" data-theme="d">Last Name:</label>
<input type="text" id="lname" name="lname" data-theme="d" placeholder="Enter Last Name" required>
</div>
<div data-role="fieldcontainer">
<label for="email" data-theme="d">E-mail Address:</label>
<input type="email" id="email" name="email" data-theme="d" placeholder="Enter Email" required>
</div>
Upvotes: 3
Views: 11274
Reputation: 111
I recommend using the following code for JQM 1.4:
error.appendTo(element.closest('.ui-field-contain'));
Upvotes: 0
Reputation: 57105
jQuery.validator.setDefaults({
errorPlacement: function(error, element) {
error.appendTo(element.parent().prev());
}
});
CSS
.error{
color:red;
display:block; //to show error message in new line
}
errorPlacement: function (error, element) {
error.appendTo(element.parent().parent().after());
},
another way DEMO
Reference
http://jqueryvalidation.org/validate/
Upvotes: 8