kissygalleryteam / auth Goto Github PK
View Code? Open in Web Editor NEW表单验证组件
表单验证组件
Auth默认规则很多触发不了校验,(mobile,equal-field)
ie6.7,8,9中在input上设置required属性,在最后验证时完全无效,求解决方法
看了下源码,定位在:
https://github.com/kissygalleryteam/auth/blob/master/1.5/lib/index.js#L226-L254
//最后一个Field的PROMISE(说明所有的Field都验证了一遍)
PROMISE.then(function(){
if(!errorFields.length){
//所有filed验证通过
_defer.resolve(fields);
self.fire('success',{fields:fields});
}
}).fail(function(){
//有一个Field验证失败,就可以派发auth的失败事件
_defer.reject(errorFields);
self.fire('error',{fields:errorFields});
});
return _defer.promise;
在一个input元素上同时应用了表单验证和自动完成两个组件, input元素blur时触发表单验证, focus时触发自动完成, 当触发自动完成在弹出的div中选择值时又会触发该表单的blur事件,导致弹出验证提示, 想阻止input在blur时触发表单验证, Field对象有个event属性可以用来绑定触发验证的事件,我设置了但是没有效果,在event属性值已改变的情况下blur事件还是会触发, 该如何才能解决呢?
var auth = new Auth('#search-form', {
stopOnError:true
});
auth.plug(new AuthMsgs());
auth.render();
var orgField = auth.field('org');
console.log(orgField.get('event')); //显示blur
orgField.set('event','submit');
console.log(orgField.get('event')); //显示submit
大犇 (2013-11-12 23:09:13):
var form = new Auth('#J_form',{submitTest:false});
$("#J_queryBtn").on("click",function(){
form.test().then(function(){
//校验成功后执行
alert("success");
}).fail(function(){
//校验失败后执行
alert("fail");
});
});
大神们,为什么每次点击J_queryBtn按钮,都是第一次的状态
第一次校验成功,后面都调用then。。
大犇 (2013-11-12 23:10:41):
第一次校验失败,后面都调用fail。。为什么。。需要清状态吗?
这个验证结果怎么取?
当一个input从页面删除以后它的验证还在,会出现验证不通过的情况
是否改成当前input不存在以后不去验证会更合理
var S = KISSY;
S.use('gallery/auth/1.6/,gallery/auth/1.6/plugin/msgs/,gallery/auth/1.6/plugin/msgs/style.css', function(S, Auth, AuthMsgs) {
var auth = new Auth('#J_Auth', {
warn: 'sidebd'
});
auth.plug(new AuthMsgs());
auth.render();
});
不起作用,我想让消息框出现在右边
就是input 是动态添加的,这个时候我要怎么给这个input加上验证呢
ps: 表单就是那种多行模式,我试过重新auth.render() 这样会给之前添加过验证的input多加一次验证
或者更改提示方式?
gallery/auth/1.6/index is not loaded! can not find module in path
gallery/auth/1.6/plugin/msgs/index is not loaded! can not find module in path
很多时候在使用表单提交的时候是在所有验证都处理完成之后进行表单数据的提交,并且使用ajax对表单的数据进行提交,但是在使用auth.on('success', function() {})的时候出现了问题是:在url地址上出现了所有传参的显示,auth插件有没有更好的方式来处理这样的问题?
如题
是不是可以加个配制什么的来控制是否要form.submit();
建议修改为hasAttr()方法,如果输入框直接设定了一个 required属性时,IE8以下仍然是undefined,造成不能验证的BUG。
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.