gpt4 book ai didi

extjs - 绑定(bind)窗口按钮以进行表单验证

转载 作者:行者123 更新时间:2023-12-03 09:12:49 25 4
gpt4 key购买 nike

我尝试在按钮上使用 formBind: true 来根据表单的验证状态在模式窗口上启用/禁用它。

我希望用户必须确认认证编号,并且验证工作正常。但是我无法将按钮绑定(bind)到验证状态。我尝试在文本字段上连接一些事件处理程序来手动处理此问题,但没有事件处理程序触发。

请参阅此 fiddle 以获取正在运行的代码: https://fiddle.sencha.com/#fiddle/1jrj

Ext.define('MyApp.view.util.dialogs.Accreditation', {
extend: 'Ext.window.Window',
title: '',
config: {
name: ''
},
modal: true,


initComponent:function() {
var me = this;


this.title = this.name + ' Accreditation';

var accreditation1 = new Ext.form.TextField( {
fieldLabel: 'Accreditation',
growMin: 250,
allowBlank: false
});

// doesn't fire
// accreditation1.addListener('activate', function(dis , eOpt) {Ext.Msg.alert("woopy twang");}, this);


var accreditation2 = new Ext.form.TextField( {
fieldLabel: 'Confirm',
growMin: 250,
allowBlank: false,
validator: function(value){
if (accreditation1.getValue() != value){
return 'Accreditation numbers must match.'
}
return true;
}
});


var button1 = new Ext.button.Button({
xtype: 'button',
text: 'OK',
itemId: 'btnOK',
formBind: true

});


var button2 = new Ext.button.Button({
xtype: 'button',
text: 'Cancel',
itemId: 'btnCancel',
handler: function() {
this.up('window').close();
}
});

this.items = [
{
html: '<h5>Enter your Accreditation Number for ' + this.name + '</h5>'
},
accreditation1,
accreditation2
]

this.buttons = [
button1,button2
]



me.callParent(arguments);
},
handlers: {
activate : function(dis, opts) {
Ext.Msg.alert('activate');
}
}


});

最佳答案

问题是您没有模板。 From the docs :

When inside FormPanel, any component configured with formBind: true will be enabled/disabled depending on the validity state of the form.

您的示例不包含表单面板。如果您将表单面板放入窗口中,并将按钮放入表单中,而不是放入窗口中,则它可以工作:

    this.layout='fit';
this.items = [{
xtype:'form',
items:[
{
html: '<h5>Enter your Accreditation Number for ' + this.lenderName + '</h5>'
},
accreditation1,
accreditation2
],
buttons: [
button1,button2
]
}]

关于extjs - 绑定(bind)窗口按钮以进行表单验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40445028/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com