开发者

javascript form validation - positioning

I have little snippet for validatin' my form. I need help to position the error messages, because now all message appear in the filed, so the user can't see it, and so its very annoying.

$(document).ready(function() {
jQuery.validator.addMethod("lettersonly", function(value, element) {
        return this.optional(element) || /^[a-zőöüóúéáűí ]+$/i.test(value);
}, "<?php echo $lettersonly; ?>");  
    $("#regval").validate({
        rules: {
            name: {
                required: true,
                minlength: 5,
                maxlength:30,
                lettersonly: true
            },
            nick: {
                required: true,
                minlength: 3,
                maxlength:12
            },
            pass1: {
                required: true,
                minlength: 5
            },
            pass2: {
                required: true,
                minlength: 5,
                equalTo: "#pass1"
            },

          messages: {
            full: {
                required: ".....",
                minlength: "....",
                maxlength: "...."
            },
            nick: {
                required: "....",
                minlength: "....",
                maxlength: "...."
            },
            pass1: {
                required: "....",
           开发者_开发技巧     minlength: "..."
            },
            pass2: {
                required: "....",
                minlength: "....",
                equalTo: "...."
            },

    });

});
</script>


"filed"?

Without really understanding where your error messages show up I suggest you check the documentation.

jQuery Validation Plugin: Options Documentation

There are several options/methods you can use to modify the default error generation / placement of the plugin.

errorElement: if the error shouldn't be a label

wrapper & errorLabelContainer: If you e.g. want a ul/li's somewhere specific where all errors should show instead of being placed right near the input field which has the error

errorPlacement (function): Called exactly once when the input validated has an error. With this function you can place the error element where ever you want. All subsequent error messages for the same input are shown in the same place afterwards

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜