extjs 验证 OR config options 外部设置 。。。

chuailong 2009-05-22 03:29:18
在用extjs 如何异步(ext.ajax.request)验证提交数据中,和数据库中无重复值。

我通过apply 定义了 vtype 类似例子:

/*
* Ext JS Library 2.1
* Copyright(c) 2006-2008, Ext JS, LLC.
* licensing@extjs.com
*
*http://extjs.com/license
*/

// Add the additional 'advanced' VTypes
Ext.apply(Ext.form.VTypes, {

password: function(val, field) {
if (field.initialPassField) {
var pwd = Ext.getCmp(field.initialPassField);
return (val == pwd.getValue());

}
return true;
},

passwordText: 'Passwords do not match'
});


Ext.onReady(function(){

Ext.QuickTips.init();

// turn on validation errors beside the field globally
Ext.form.Field.prototype.msgTarget = 'side';

var bd = Ext.getBody();

/*
* ================ Date Range =======================
*/



var pwd = new Ext.FormPanel({
labelWidth: 125,
frame: true,
title: 'Password Verification',
bodyStyle:'padding:5px 5px 0',
width: 350,
defaults: {
width: 175,
inputType: 'password'
},
defaultType: 'textfield',
items: [{
fieldLabel: 'Password',
name: 'pass',
id: 'pass'
},{
fieldLabel: 'Confirm Password',
name: 'pass-cfrm',
vtype: 'password',
initialPassField: 'pass' // id of the initial password field
}]
});

pwd.render(bd);
});

我在其中加了异步请求服务的内容,查询是否有该记录,但是返回的success 中怎么样VTypes return true 或 false啊?

异步的值没法赋值啊, 在success:中返回不可以。

我又在textfield 中 做监听 可是返回的值也没办法 配置到 textfield 中的 config options 中,

晕了 忙一下午了,说的挺乱,那位兄弟提供一个有后台的验证不可以重复值的例子。
...全文
151 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
Go 旅城通票 2009-05-25
  • 打赏
  • 举报
回复
去另外的帖子看我的回复
qintao1203 2009-05-25
  • 打赏
  • 举报
回复
Vtype
貌似不能异步验证!
HNsnopy 2009-05-23
  • 打赏
  • 举报
回复
我从昨天晚上看到现在都没看明白楼主是啥意思.....呵呵.
xiaojing7 2009-05-23
  • 打赏
  • 举报
回复
看不懂,确实比较乱

放在外面,和传值有什么关系?
向 *.js文件传值?


<script type="text/javascript">
function getCurrParam(arg) {
var scripts = document.getElementsByTagName("script");
var currentScript = scripts[scripts.length - 1];

var uri = currentScript.getAttribute("src");
uri = uri.substr(uri.indexOf("?") ,uri.length - uri.indexOf("?") + 1);

var re = new RegExp(""+ arg +"\=([^\&\?]*)", "ig");
return ((uri.match(re))?(uri.match(re)[0].substr(arg.length+1)):null);
}
</script>


<script type="text/javascript" src="test.js?id=xiaojing7&alias=枯井"></script>




test.js
=================
var id = getCurrParam("id") ,alias = getCurrParam("alias");
alert("您传过来的id为:"+ id +",alias为:"+ alias);
chuailong 2009-05-23
  • 打赏
  • 举报
回复
上面说的很乱大概就是下面得问题


我用vtype和apply定义了新的验证,验证要异步查询后台的数据,然后返回true或false,但是在vtype中使用的
Ext.Ajax.request返回的success true或false ,由于是异步的就不能赋予其它变量,也就不能在vtype中判断对错(它接受返回true或false,但在success中的返回时无效的)。
在这样情况下我想,我想在success直接设置当前form提交数据错误,或但前vtype 的提交错误。


哎有点乱,我把Ext.Ajax.request放到外面textfile的监听中,但也是这样不能传值啊。
chuailong 2009-05-22
  • 打赏
  • 举报
回复
自己先顶下

52,797

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 Ajax
社区管理员
  • Ajax
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧