复选框的验证规则:如何在其他地方显示?

时间:2016-03-12 18:50:28

标签: jquery html css validation error-handling

如此图所示,复选框的错误消息搞砸了。如何在其他地方显示此内容,仅用于复选框字段?

Checkbox error message messedup

这是我使用的一些代码。

$(function() {  
$("#reservation").validate({    
    rules: {
        "room[]": {
            required: true
          },
        start: "required",
        end: "required",
        name: "required",
        phone: {
        required: true,
        digits: true,
        minlength: 10,
        maxlength: 14
        },
        email: {
            required: true,
            email: true
        },
        address: "required"
    },        
    messages: {
        "room[]": {
            required: "Please select a room <br/>"
          },
        start: "Select date in ROOM AVAILABILITY",
        end: "Select date in ROOM AVAILABILITY",
        name: "Enter your full name",
        phone: {
        required: "Phone number is required",
        digits: "This is not a numeric value",
        minlength: "Number is too short",
        maxlength: "Number is too long"
        },
        email: "Please enter a valid email address",
        address: "Address is required"
    },              
      submitHandler: function(form) {
        form.submit();
    }
});

});

我的复选框字段是:

<input type="checkbox" name="room[]" value="'.$id.'"> $name.$desc

感谢您的时间和帮助。

1 个答案:

答案 0 :(得分:1)

你的问题的答案实际上是在插件验证({});本身。

规则设置在那里,不幸的是我不认为你改变它因此我建议你将复选框移动到名称的右侧。

例如

1. <input type="checkbox" name="room[]" value="'.$id.'"> Delux for 1 Person<br/><br/>

Becomes <br/><br/>

1. Delux for 1 Person <input type="checkbox" name="room[]" value="'.$id.'"> 

希望这会有所帮助。