extJs中关于formPanel动态添加组件的验证问题

[color=violet]1.在用extJs的formPanel动态添加组件的时候,发现动态添加的组件验证没法通过,网上找了半天才将这个问题解决。
1.源代码如下:
Ext.onReady(function() {
Ext.QuickTips.init();
testWin = new Ext.Window({
func: "null",
title: "题库信息",
width: 500,
height: 420,
maximizable: true,
closeAction: "hide",
resizable: false,
plain: true,
modal: true,
layout: "fit",
items:{
xtype: "form",
id: "testForm",
layout: "form",
frame: true,
border: false,
autoScroll: true,
labelWidth: 90,
width: 900,
items: [
new Ext.form.FieldSet({
name: 'testFieldSet',
autoHeight: true,
items: [
{
layout:'column',
items:[
{
columnWidth : .9, // 该列有整行中所占百分比
layout : "form",
items : [
{
xtype : "textfield",
anchor: '90%',
name : "testtextvalid",
fieldLabel: "testDyn",
value:null,
allowBlank: false
}
]
},
{
columnWidth : .1, // 该列有整行中所占百分比
layout : "form",
items : [{
xtype:"button",
anchor: '90%',
text:"删除",
handler:function(){
var testForm = testWin.get("testForm");
testForm.remove(this.ownerCt.ownerCt.ownerCt);
}
}]
}
]
}
]
})
]
},
buttons: [
{
text: "添加选项",
width: 80,
handler: function() {
var testForm = testWin.get("testForm");
var testFieldSet = new Ext.form.FieldSet({
name: 'testFieldSet',
autoHeight: true,
items: [
{
layout:'column',
items:[
{
columnWidth : .9, // 该列有整行中所占百分比
layout : "form",
items : [
{
xtype : "textfield",
anchor: '90%',
name : "testtextvalid",
fieldLabel: "testDyn",
value:null,
allowBlank: false
}
]
},
{
columnWidth : .1, // 该列有整行中所占百分比
layout : "form",
items : [{
xtype:"button",
anchor: '90%',
text:"删除",
handler:function(){
var testForm = testWin.get("testForm");
testForm.remove(this.ownerCt.ownerCt.ownerCt);
}
}]
}
]
}
]
});
testForm.add(testFieldSet); //add the fieldset to the formpanel
testFieldSet.doLayout();
testForm.doLayout();
// 以下是关键代码
testFieldSet.form = testForm.getForm();
testForm.initFields.call(testFieldSet);
}
},{
text: "确定",
width: 80,
handler: function() {
// 进行验证
var valid = testWin.get("testForm").getForm().isValid();
alert(valid);
}
}],
listeners: {
show: function(obj) {
// 题目信息窗口输入信息验证
Ext.form.Field.prototype.msgTarget = "under";
// 默认校验,必填项标红
testWin.get("testForm").getForm().isValid();
},
hide: function(obj) {
// 表单重置
testWin.get("testForm").getForm().reset();
}
}
});
function showWin(){
testWin.show();
}
showWin();
});
//]]>
</script>[/color]
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值