开发者

how to use jquery validation plugin to view the label specific message at the top?

开发者 https://www.devze.com 2023-01-23 23:40 出处:网络
I am using jquery validation plugin to display error message in the top instead instead of beside the labels.say, i have address , city, zip code ....if user don\'t enter anything i have to display th

I am using jquery validation plugin to display error message in the top instead instead of beside the labels. say, i have address , city, zip code ....if user don't enter anything i have to display the error message at top in a div like " please enter valid address" , "please enter valid city" etc... how can I override the default behavior of the plugin .....any help will be ap开发者_如何学Cpreciated ... thanks!


You can use errorLabelContainer and wrapper options for this:

$("form").validate({
  errorLabelContainer: "#someElementUpTop", //a <ul> element for example
  wrapper: "li" //display them in a list
});

errorLabelContainer determines where the error elements are added, wrapper determines what they're wrapped in. In this case #someElementUpTop is a <ul> to append the <li> wrapped labels to...so clicking still goes to the correct element in the page that has the validation error. If you need another element above this, say a <div> that hides and shows appropriately when there are/aren't errors, add a errorContainer: "#someDiv" option as well.

0

精彩评论

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