1

i'm using the follow below to display error message next to each unfilled field. I'd like to simplify things and just have a ErrorBox appear that says "Please fill in all fields" when the submit button is clicked and fields are not filled. class="required" is being used on each field type that is required. how would I do this, do I use showError ?

<script type="text/javascript">
$(document).ready(function() {
    $("#form1").validate({
        errorLabelContainer: $("#form1 div.error")
    });
</script>
2

2 Answers 2

2
Code

Displays a message above the form, indicating how many fields are invalid when the user tries to submit an invalid form.

$(".selector").validate({
invalidHandler: function(form, validator) {
  var errors = validator.numberOfInvalids();
  if (errors) {
    var message = errors == 1
      ? 'You missed 1 field. It has been highlighted'
      : 'You missed ' + errors + ' fields. They have been highlighted';
    $("div.error span").html(message);
    $("div.error").show();
  } else {
    $("div.error").hide();
  }
}
 })

instead of using a div use another jquery library that can display a pop up window with the same error message

Sign up to request clarification or add additional context in comments.

2 Comments

i'm trying to do a dialog popup box. I have no problem displaying the error in a div like in my original post.
use jquery dialog instead of $("div.error").show(); use $("div.error").dialog(); and that's a link for the api jqueryui.com/demos/dialog
0

The validate plugin has invalidHandler: function(e, validator) which will suit your needs.

A small demo: http://jsfiddle.net/codovations/5YHQb/1/

2 Comments

how would I apply this, I can't find a sold good example for this. is this better than ShowError?
@acctman: updated code. good question btw. thanks to you, i have a small snippet of my own to show error summary is popup.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.