如何根据 ExtJs 中的某些条件启用禁用的文本字段?

Ank*_*ita 2 extjs

我尝试使用此代码

listeners : {
  afterrender : function(comp) {
    var countryValue = data.countryCode;
    if (countryValue == "AU" && Ext.isEmpty(comp.getValue())) {
        Ext.getCmp('state').markInvalid('When Country is AU, State is mandatory.');
        Ext.getCmp('state').enable();
        comp.inputValue = true;
    } else {
        comp.clearInvalid();
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

状态字段最初是禁用的。只有当 country 字段取值为“AU”时,才需要启用 state 字段。

Kut*_*tty 5

而不是 enable(),你需要给 setdisabled(false);

listeners : {
afterrender : function(comp) {
var countryValue = data.countryCode;
if(countryValue == "AU" && Ext.isEmpty(comp.getValue())){
    Ext.getCmp('state').markInvalid('When Country is AU, State is mandatory.');
    Ext.getCmp('state').setdisabled(false);
    comp.inputValue = true;
}else{
    comp.clearInvalid();
}
}
}
Run Code Online (Sandbox Code Playgroud)