0
我定义了一个验证,它控制着id是唯一的还是不绑定按钮。它很好地与内置验证很好,但它不绑定我自己的验证。Ext JS 4.1 - 用户定义的验证不绑定按钮
这是我已经试过:
视图 - FormPanel中:
Ext.define(appName + '.view.user.UserForm', {
extend: 'Ext.form.Panel',
requires: [appName + '.view.language.LanguageCombo'],
alias: 'widget.userform',
// title : 'User Form',
iconCls: 'icon-form',
frame: true,
padding: '5 5 0 5',
border: true,
buttonAlign: 'right',
width: '100%',
// height : 200,
monitorValid: true,
bodyPadding: 10,
fieldDefaults: {
labelAlign: 'left',
labelWidth: 110,
anchor: '98%',
allowBlank: false,
selectOnFocus: true,
msgTarget: 'side'
},
initComponent: function() {
var me = this;
this.title = bundle.getMsg('userform.title');
this.items = [{
xtype: 'numberfield',
minValue: 1,
fieldLabel: bundle.getMsg('userform.field.recordId'),
name: 'recordId',
itemId: 'recordId'
}, {
];
this.btnReset = Ext.create('Ext.ux.button.ResetButton', {
handler: function (btn) {
me.getForm().reset();
}
});
this.btnSubmit = Ext.create('Ext.ux.button.SaveButton', {
disabled: true,
formBind: true
});
this.buttons = [me.btnReset, me.btnSubmit];
this.callParent(arguments);
}
});
控制器的方法:
var form = this.getUserForm();
if (field.getValue() && field.getValue() != '') {
Ext.Ajax.request({
url: 'user/chkRecordIdUnique.ajax',
method: 'POST',
params: {
recordId: field.getValue()
},
success: function (response, options) {
var res = Ext.decode(response.responseText);
if (!res.success) {
field.markInvalid(bundle.getMsg('record.taken'));
form.getForm().markInvalid(bundle.getMsg('record.taken'));
}
}
});
}
@Erick库感谢您的关心,但实际上这只是一个代码示例。所以我也必须检查其他领域。所以我不能手动启用或禁用表单绑定按钮,或者我应该为每个用户定义的验证执行此操作;这是没有意义的.. – talha06
如果每个字段都可以独立验证,那么可以使用同步Ajax在'field.validator'函数中执行验证。 Ext JS不支持通过'Ext.Ajax.request',所以你必须手动执行它(应该很容易设置)。我实际上不得不在最近自己做,所以这是可能的。如果字段依赖于其他字段,那么您应该考虑删除“formBind”,并仅仅进行所有验证/启用。 – Eric
好的,非常感谢埃里克,看来我应该像你一样自己实现它。但是,如果核心图书馆做到了,它会更好;当一个标记为无效的字段(所以表单变为无效)时,也会生成一个formBind:true的按钮。 – talha06