简体   繁体   English

如何从 SENCHA/ext js 中的另一个组合框启用组合框?

[英]How to enable a combobox from another combobox in SENCHA/ext js?

I need to change something in Sencha, I need to add a second combobox that in the begining must be disable, that's ok no problem with that, but then I need that the first combobox will enable the second combobox when some items (not all) from the first combo is selected, it looks very simple.我需要在 Sencha 中更改某些内容,我需要添加一个开始时必须禁用的第二个组合框,没关系没问题,但是我需要第一个组合框在某些项目(不是全部)时启用第二个组合框从第一个组合被选中,看起来很简单。

Here is the code:这是代码:

var formPanel = new Ext.form.FormPanel({
  id: 'formanchor-form',
  title: 'Nuevo Gasto',
  bodyStyle: 'padding:5px 5px 0',
  width: 600,
  defaults: {
    width: 230
  },
  defaultType: 'textfield',
  renderTo: 'formulario',
  frame: true,
  items: [{
    xtype: 'combo',
    typeAhead: true,
    name: 'cboGasto',
    id: 'cboGasto',
    fieldLabel: 'Gastos',
    store: storeCbo,
    displayField: 'gasto',
    valueField: 'codigo',
    allowBlank: false,
    width: 250,
    mode: 'local',
    triggerAction: 'all',
    emptyText: 'SELECCIONE',
    blankText: 'Debe seleccionar un gasto',
    forceSelection: true
  }, {
    xtype: 'numberfield',
    fieldLabel: 'Monto',
    name: 'txtMonto',
    id: 'txtMonto',
    maxLength: 7,
    allowBlank: false,
    minValue: 100,
    minText: 'El monto mínimo es 100',
    maxValue: 9999999,
    maxLengthText: 'El monto máximo es 9.999.999',
    blankText: 'El monto es requerido',
    width: 100
  }, {
    xtype: 'combo',
    typeAhead: true,
    name: 'CboDeudasReceptor',
    id: 'CboDeudasReceptor',
    fieldLabel: 'Receptor',
    store: storeCboR,
    displayField: 'receptor',
    valueField: 'codigo',
    allowBlank: false,
    width: 250,
    mode: 'local',
    triggerAction: 'all',
    emptyText: 'SELECCIONE',
    blankText: 'Debe seleccionar un Receptor',
    forceSelection: true,
    disabled: true
  }],
  buttons: [{
    text: 'Agregar',
    handler: function() {
      var mon = Ext.getCmp('txtMonto').getValue();
      var gas = Ext.getCmp('cboGasto').getValue();
      if (mon.length == 0) {
        Ext.MessageBox.alert('Monto del Gasto', 'Debe Ingresar un monto para el gasto.');
        Ext.getCmp('txtMonto').focus();
        return false;
      }
      if (gas.length == 0) {
        Ext.MessageBox.alert('Gasto', 'Debe Seleccionar un gasto.');
        Ext.getCmp('cboGasto').focus();
        return false;
      }
      location.href = 'ingresa_gastos_lib.asp?cboGasto=' + gas + '&txtMontoPesos=' + mon + '&' + params();
    }
  }, {
    text: 'Volver',
    handler: function() {
      location.href = 'datos_deuda.asp?' + params();
    }
  }]
});

UPDATE:更新:

If I put a listener in the first combo, then works partial like I want it, but the 2nd combo just work the dropdown but still looks like disabled, and I can´t edit.如果我在第一个组合中放置了一个监听器,那么它会像我想要的那样部分工作,但是第二个组合只是在下拉菜单中工作,但仍然看起来像被禁用了,我无法编辑。 So the question now would be: How to put the 2nd combobox full operational.所以现在的问题是:如何让第二个组合框全面运作。

listeners: {
  select: function(combo, record, index) {
    if (Ext.getCmp('cboGasto').getRawValue() == 'RECEPTOR: EMBARGO') {
      alert(Ext.getCmp('cboGasto').getRawValue());
      Ext.getCmp('CboDeudasReceptor').disabled = false;
    }
  }
}

Setting the disabled field to false does not a solution.disabled字段设置为 false 不是解决方案。 It is just changing the value of the property in the object, but all visual styles are still there.它只是改变了对象中属性的值,但所有的视觉样式仍然存在。 You should use setDisabled() method of the combobox, or enable() and disabled() methods.您应该使用组合框的setDisabled()方法,或enable()disabled()方法。 So your listener should look like the following:因此,您的侦听器应如下所示:

select: function (combo, record, index) {
    if (Ext.getCmp('cboGasto').getRawValue()=='RECEPTOR: EMBARGO'){
            alert(Ext.getCmp('cboGasto').getRawValue());
            Ext.getCmp('CboDeudasReceptor').setDisabled(false);
            //Or Ext.getCmp('CboDeudasReceptor').enable();
        }
    }
}
items:[{
    xtype: "combobox",
    name: "TubeWellId",
    fieldLabel: "Tubewell",
    store: tube_well_store,
    allowBlank: false,
    displayField: "TubeWellName",
    valueField: "TubeWellId",
    queryMode: "local",
    forceSelection: true,
    listeners: {
        select: function (combo) {
            var getForm = this.up("form").getForm();
            if (combo.getValue() === 1) {
                getForm.findField("TubeWellDistance").setReadOnly(true);
            } else {
                getForm.findField("TubeWellDistance").setReadOnly(false);
            }
        }
    }
}, {
    xtype: "combobox",
    name: "TubeWellDistance",
    fieldLabel: "Tubewell Distance",
    store: tube_well_store,
    allowBlank: false,
    displayField: "DistanceName",
    valueField: "DistanceId",
    queryMode: "local",
    forceSelection: true,
}]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM