Custom Error Label Placement using jQuery validate (For all or some of your errors)

后端 未结 4 1816
执笔经年
执笔经年 2020-12-12 14:07

I would like to place one error label (Not All) in a custom location. jQuery provides this http://docs.jquery.com/Plugins/Validation/validate#toptions optio

4条回答
  •  死守一世寂寞
    2020-12-12 15:04

    This is a more generic solution, not specific to the OP's HTML structure.

    If you only want one particular error label in a different location while the rest remain in their default placement, try this...

    $("#myform").validate({
      errorPlacement: function(error, element) {
         if (element.attr("name") == "myFieldName") {
    
           // do whatever you need to place label where you want
    
             // an example
             error.insertBefore( $("#someOtherPlace") );
    
             // just another example
             $("#yetAnotherPlace").html( error );  
    
         } else {
    
             // the default error placement for the rest
             error.insertAfter(element);
    
         }
       }
    });
    

    Online Documentation for errorPlacement: option

提交回复
热议问题