ExtJS - 根据输入值禁用
ExtJS - disable depending on input value
我有下面的代码可以在表单中创建一个文本字段。
buildForm : function() {
this.time = new Ext.form.TextField({
name : 'estimate',
allowBlank : false,
fieldLabel : 'Estimate',
onBlur : function(field) {
return this.setValue(this.getValue().replace('.', ','));
}
});
}
它工作正常。
现在,当我渲染这个表单时,这个字段是 value="abc"
,我需要设置 disabled
到这个字段。
我试过了:
disabled : function() { return this.getValue() == 'abc' ? true : false;}
disabled : function(field) { return this.getValue() == 'abc' ? true : false;}
disabled : function(field) { return field.getValue() == 'abc' ? true : false;}
disabled : this.getValue() == 'abc' ? true : false
但这项工作没有任何意义。有什么想法吗?
试试这个
change: function(field, newValue,) {
field.setDisabled(newValue == 'abc');
}
勾选API for more info on events, methods for TextField
UPD:
如果您只需要在表单渲染时禁用文本字段,只需在 buildForm 函数中添加这一行。
this.time.setDisabled(this.time.getValue() == 'abc')
另一种方法是在 TextField 的 render 事件上添加逻辑。
render: function(field) {
field.setDisabled(field.getValue() == 'abc')
}
更新 2:
我想,你的问题是在设置值或顺序上。
这是一个工作示例。
通知this.time.setValue('abc')
而不是 this.time.value = 'abc',这是行不通的。
buildForm: function() {
this.timeFld = Ext.create('Ext.form.TextField', {
name: 'estimate',
allowBlank: false,
fieldLabel: 'Estimate',
onBlur: function(field) {
return this.setValue(this.getValue().replace('.', ','));
},
listeners: {
render: function(field) {
field.setDisabled(field.getValue() == 'abc');
}
}
});
this.timeFld.setValue('abc');
// this.time.setDisabled(this.time.getValue() == 'abc');
Ext.create('Ext.form.Panel', {
title: 'Test',
items: [
this.timeFld
],
renderTo: Ext.getBody()
});
// alert(this.timeFld.getValue());
}
我有下面的代码可以在表单中创建一个文本字段。
buildForm : function() {
this.time = new Ext.form.TextField({
name : 'estimate',
allowBlank : false,
fieldLabel : 'Estimate',
onBlur : function(field) {
return this.setValue(this.getValue().replace('.', ','));
}
});
}
它工作正常。
现在,当我渲染这个表单时,这个字段是 value="abc"
,我需要设置 disabled
到这个字段。
我试过了:
disabled : function() { return this.getValue() == 'abc' ? true : false;}
disabled : function(field) { return this.getValue() == 'abc' ? true : false;}
disabled : function(field) { return field.getValue() == 'abc' ? true : false;}
disabled : this.getValue() == 'abc' ? true : false
但这项工作没有任何意义。有什么想法吗?
试试这个
change: function(field, newValue,) {
field.setDisabled(newValue == 'abc');
}
勾选API for more info on events, methods for TextField
UPD:
如果您只需要在表单渲染时禁用文本字段,只需在 buildForm 函数中添加这一行。
this.time.setDisabled(this.time.getValue() == 'abc')
另一种方法是在 TextField 的 render 事件上添加逻辑。
render: function(field) {
field.setDisabled(field.getValue() == 'abc')
}
更新 2:
我想,你的问题是在设置值或顺序上。
这是一个工作示例。
通知this.time.setValue('abc') 而不是 this.time.value = 'abc',这是行不通的。
buildForm: function() {
this.timeFld = Ext.create('Ext.form.TextField', {
name: 'estimate',
allowBlank: false,
fieldLabel: 'Estimate',
onBlur: function(field) {
return this.setValue(this.getValue().replace('.', ','));
},
listeners: {
render: function(field) {
field.setDisabled(field.getValue() == 'abc');
}
}
});
this.timeFld.setValue('abc');
// this.time.setDisabled(this.time.getValue() == 'abc');
Ext.create('Ext.form.Panel', {
title: 'Test',
items: [
this.timeFld
],
renderTo: Ext.getBody()
});
// alert(this.timeFld.getValue());
}