Jquery Validation plugin : Custom error messages not showing
I am using jquery validation for validating input for my form. However I have specified my custom messages, but still general messages are being displayed when clicking on submit page. Here is code for the form: Am I missing something or doing incorrectly:
<script language="javascript" type="text/javascript">
$(document).ready(function () {
$("#emailForm").validate({ rules: {
FromMail: {
required: true,
email: true
}
},
messages: {
FromMail: {
required: "Please enter From email address.",
email: "Please enter valid From Email address."
}
},
errorPlacement: function (error, element) {
alert("errorPlacement");
error.appendTo(element.next());
},
showErrors: function (errorMap, errorList) {
alert("showErrors");
}
});
});
function sendMail()
{
$("#emailDialog").dialog({ modal: true,
buttons: { "Send": function () {
//$("#FromMail").addClass("ui-state-error");
if ($("#emailForm").validate().form() == true) {
$.getJSON($("#emailForm").attr("action"),
$("#emailForm").serialize(),
function (data) {
alert(data);
});
}
},
"Cancel": function () { $("#emailDialog").dialog("close"); }
}
});
}
</script>
}
<body>
<div id="emailDialog" title="Email" style="display:none">
<form id="emailForm" action="@Url.Action("SendMail", "Content")" method="get" >
<div class="editor-label">
<label for="FromMail">From Email</label>
</div>
<div class="editor-field">
<input id="FromMail" name="FromMail" style="width:200px" class="required email" type="text" value="" />
<span class="field-validation-valid" data-valmsg-for="FromMail" data-valmsg-replace="true"></span>
</div>
<div class="editor-label">
<label for="ToEmailList">To Email Address</labe开发者_如何学编程l>
</div>
<div class="editor-field">
<textarea cols="20" id="ToEmailList" name="ToEmailList" rows="2" class="required email" style="width:200px">
</textarea>
<span class="field-validation-valid" data-valmsg-for="ToEmailList" data-valmsg-replace="true"></span>
</div>
精彩评论