在更改/检查ExtJS广播组上的事件之前,请您帮助我。我希望在根据情况更改单选按钮之前应检查一些事件。如果条件显示为false,我需要允许用户更改“选择另一个”单选按钮,然后我们只需要选择旧的单选按钮。
请参考以下代码:
Ext.application({
name: 'Fiddle',
launch: function () {
Ext.create('Ext.form.Panel', {
title: 'RadioGroup Example',
width: 300,
height: 125,
bodyPadding: 10,
renderTo: Ext.getBody(),
items: [{
xtype: 'radiogroup',
fieldLabel: 'Gender',
columns: 1,
items: [{
boxLabel: 'Male',
name: 'rb',
inputValue: '1'
}, {
boxLabel: 'Female',
name: 'rb',
inputValue: '2',
}],
listeners: {
change: function(field, newValue, oldValue, eOpts) {
console.log(newValue);
alert(newValue.rb);
},
}
}]
});
}
});
如评论中所述,没有beforechange
事件可用于否决更改。
其他一些选项是:
您可以使change
侦听器验证无线电组,如果选择了不正确的选项,则使其无效。这样一来,用户就会被动地得知存在问题,因此必须对其进行修复。
您可以通过使用oldvalue
参数获得您描述的行为,只需将无线电控件设置回旧值即可:
change: function(field, newValue, oldValue, eOpts) {
if (<new value isn't acceptable>) {
// Probably should let the user know why
field.setValue(oldValue);
return;
}
... any other change logic here.
}
change
侦听器启用和禁用选项,从而避免了用户一开始就做出错误的选择。