jQuery-validate error messages in Twitter ...
http://www.jefclaes.be/2012/11/jquery-validate-error-messages-in.html
something satisfactory.
In this example, I have a bootstrapped form that looks like this.
@using (Html.BeginForm("ChangePassword", "Account", FormMethod.Post, new { @class = "form-horizontal"})) {
<div class="control-group">
<label class="control-label">Old password</label>
<div class="controls">
@Html.PasswordFor(m => m.OldPassword)
</div>
</div>
<div class="control-group">
<label class="control-label">New password</label>
<div class="controls">
@Html.PasswordFor(m => m.NewPassword)
</div>
</div>
<div class="control-group">
<label class="control-label">Confirm password</label>
<div class="controls">
@Html.PasswordFor(m => m.ConfirmPassword)
</div>
</div>
<div class="control-group">
<div class="controls">
<button type="submit" class="btn btn-primary">Change password</button>
</div>
</div>
}
To make the error messages show up in tooltips on the input controls, I eventually ended up with the snippet below.
$.validator.setDefaults({
showErrors: function (errorMap, errorList) {
this.defaultShowErrors();
// destroy tooltips on valid elements
$("." + this.settings.validClass)
.tooltip("destroy");
// add/update tooltips
for (var i = 0; i < errorList.length; i++) {
var error = errorList[i];
$("#" + error.element.id)
.tooltip({ trigger: "focus" })
.attr("data-original-title", error.message)
}
}
});
I'm setting a custom showErrors function to extend the behaviour of the jQuery validator. I don't want to lose the default behaviour (highlighting etc), so I start with invoking the default showErrors function, to then destroy the tooltip on all valid input elements and to finally add or update the tooltip and its title on all invalid input elements. The errorList argument holds all the information I need for this; an array of invalid elements and their corresponding error messages.
[Object, Object]
> 0: Object
>> element: <input>
>> message: "The Current password field is required."
> 1: Object
>> element: <input>
>> message: "The New password field is required."
> length: 2
The end result looks like this.
jQuery-validate error messages in Twitter ...的更多相关文章
- Jquery Validate 相关参数
Jquery Validate 相关参数 //定义中文消息 var cnmsg = { required: “必选字段”, remote: “请修正该字段”, email: “请输入正确格式的电子邮件 ...
- JQuery validate验证规则
//定义中文消息 var cnmsg = { required: “必选字段”, remote: “请修正该字段”, email: “请输入正确格式的电子邮件”, url: “请输入合法的网址”, d ...
- jQuery Validate 表单验证 — 用户注册简单应用
相信很多coder在表单验证这块都是自己写验证规则的,今天我们用jQuery Validate这款前端验证利器来写一个简单的应用. 可以先把我写的这个小demo运行试下,先睹为快.猛戳链接--> ...
- jquery validate表单验证插件-推荐
1 表单验证的准备工作 在开启长篇大论之前,首先将表单验证的效果展示给大家. 1.点击表单项,显示帮助提示 2.鼠标离开表单项时,开始校验元素 3.鼠标离开后的正确.错误提示及鼠标移入时的帮 ...
- 表单验证插件之jquery.validate.js
提到表单验证的插件,第一个想到的就是jquery.validate.js,所以小生想在这里稍微详细地说一下这款插件的具体使用方法,便于理解,我直接附上整段demo的代码(没怎么调样式,主要是看js): ...
- jQuery Validate验证框架详解
转自:http://www.cnblogs.com/linjiqin/p/3431835.html jQuery校验官网地址:http://bassistance.de/jquery-plugins/ ...
- 利用jquery.validate以及bootstrap的tooltip开发气泡式的表单校验组件
表单校验是页面开发中非常常见的一类需求,相信每个前端开发人员都有这方面的经验.网上有很多成熟的表单校验框架,虽然按照它们默认的设计,用起来没有多大的问题,但是在实际工作中,表单校验有可能有比较复杂的个 ...
- jQuery验证控件jquery.validate.js使用说明
官网地址:http://bassistance.de/jquery-plugins/jquery-plugin-validation jQuery plugin: Validation 使用说明 转载 ...
- jquery.validate.js插件使用
jQuery验证控件jquery.validate.js使用说明+中文API 官网地址:http://bassistance.de/jquery-plugins/jquery-plugin-valid ...
随机推荐
- 什么是HttpOnly
1.什么是HttpOnly? 如果您在cookie中设置了HttpOnly属性,那么通过js脚本将无法读取到cookie信息,这样能有效的防止XSS攻击,具体一点的介绍请google进行搜索 2.ja ...
- !!流行的php面试题及答案
分类: 1.在PHP中,当前脚本的名称(不包括路径和查询字符串)记录在预定义变量(1)中:而链接到当前页面的URL记录在预定义变量(2)中. 答:echo $_SERVER['PHP_SELF']; ...
- UVa 11922 - Permutation Transformer 伸展树
第一棵伸展树,各种调试模板……TVT 对于 1 n 这种查询我处理的不太好,之前序列前后没有添加冗余节点,一直Runtime Error. 后来加上冗余节点之后又出了别的状况,因为多了 0 和 n+1 ...
- Hibernate学习笔记(1)
1 使用Hibernate (1)创建User Library,命名为HIBERNATE3,加入需要的jar (2)创建hibernate配置文件hibernate.cfg.xml, 为了便于调试最好 ...
- [置顶] 手机通过socket控制电脑关机,重启,注销等功能
服务端 package com.pc; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.IOE ...
- bash: ./device/nexell/tools/build.sh: 权限不够
/bin/bash: build/tools/diff_package_overlays.py: 鏉冮檺涓嶅 i686-linux-gcc: error trying to exec 'cc1': ...
- 面试题_31_to_47_JVM 底层与GC(Garbage Collection)的面试问题
31)64 位 JVM 中,int 的长度是多数?Java 中,int 类型变量的长度是一个固定值,与平台无关,都是 32 位.意思就是说,在 32 位 和 64 位 的Java 虚拟机中,int 类 ...
- asp.net实现文件解压和压缩
C#解压RAR压缩文件(--转载--测试通过) using System; using System.Collections.Generic; using System.Text; using Sys ...
- 如何在Android应用中加入广告
转载自:http://mobile.51cto.com/aprogram-387527.htm 目前我自己的一款小程序中正进行到加入广告阶段,BAIDU了一下,找到如下好文章,非常有必要共享一下,故转 ...
- LeetCode Number of Islands 岛的数量(DFS,BFS)
题意:0代表水,1代表陆地,那么被水围起来的就是岛了,给一个01矩阵,问有多少个岛? 思路:DFS还是比较短,实现了一下.如果一个点已经被遍历过了,那就将其置为0就行了,不要去搜0的. class S ...