简体   繁体   中英

How to make a separate jQuery Validation messagebox note appear compared to an appended one next to the field: at the same time

I want a asterisk to appear next to the field, and then a specific message to appear at the bottom of my form at the same time upon validation.

Currently, I have these two versions:

1) works for the asterisk appearing after the field title.

2) works for making "please fill in the last name".

However, how can I get these both to work at the same time? Currently only the one on top of the other will work if I have them both in my file at the same time.

1) APPENDed NEXT TO FIELD LABEL VERSION

$(document).ready(function() {

    // validate signup form on keyup and submit
    $("#newform").validate({



    errorPlacement: function(error, element) {
        error.appendTo('#title-' + element.attr('id'));
    },    

        rules: {
            lastname: {
                required: true, 
                minlength: 2            
            }
        },

        messages: {
            lastname: {
                required: "*",
                minlength: "*"
            }
        }
    });
});
</script>

2) MESSAGE BOX VERSION

$(document).ready(function() {

    // validate signup form on keyup and submit
    $("#newform").validate({

    errorLabelContainer: "#messageBox",
   wrapper: "li",
   submitHandler: function() { alert("Submitted!") 
   },    

        rules: {
            lastname: {
                required: true, 
                minlength: 2            
            }
        },

        messages: {
            lastname: {
                required: "please fill in last name",
                minlength: "please fix the last name"
            }
        }
    });
});
</script>

Thanks

The answer was that there can only be one validate on the page that will be recognized. jQuery's Validate plugin has the highlight option that can replace the asterisk method I was trying to implement.

Meanwhile, errorLabelContainer can get the messages in space down by the bottom of the form.

Both of those options can go into one Validate() without interfering with each other.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM