Fill a texfield from a combobox in EXTJS6

1

I had to continue a project and I have some doubts about EXTJS6 .

It happens that the one who worked before used Sencha Architech, which I do not know how to use it very well so the files I have been seeing and understanding them by hand, but even so I find it difficult to find the relationship between them and implement what I will ask them to next.

What I want to do is take a data that appears listed in a combobox that is loaded by means of a database, and from that data that I select I want to fill a textfield .

Example: select Engineering Department, and have the textfield automatically fill Engineering School (or the address where it belongs). The query of the database I have it ready since I made the union of tables and everything but the structure or trip of variables between files I do not have them clear.

As I saw, it works like this:

You have a view that declares the appearance and variables as listeners. Then it goes to a ViewController that contains the methods to be applied to these listeners. This is then linked to a model with other variables (I do not know how it works). Hence, it is linked to a storage that has variables that are passed through ajax to a php that executes the query SQL in the database.

I do not know if that is the trip of the data, or really travel in another way.

Could someone explain that process to me, and the other, if any example is possible to fill a textfield from a combobox following that structure?

I'll thank you very much

I enter the code of the combobox and the texfield for more idea:

onUnidadSelect: function(combo, record, eOpts) {
    Ext.ComponentQuery.query('combobox[name=cmb_nuevoCC]')[0].setValue('');
    Ext.ComponentQuery.query('combobox[name=cmb_nuevoSCC]')[0].setValue('');
    Ext.getStore('cc.sto_centroCosto').load({
        params:{unidad_codigo:record.data.unidad_codigo},
        callback: function(records, operation, success) {

        }
    });


    var cuenta_grid    = Ext.ComponentQuery.query('[itemId=grid_centroCosto]')[0].getStore().getCount();


    for (var i = 0; i < cuenta_grid-1; i++) {

        if (Ext.ComponentQuery.query('[itemId=grid_centroCosto]')[0].getStore().data.items[i].data.col_defecto == 'O' ){

            form_48.app.porcentaje_distrib = Ext.ComponentQuery.query('[itemId=grid_centroCosto]')[0].getStore().data.items[i].data.distribucion_codigo;

            var monto_origen = Ext.ComponentQuery.query('[itemId=grid_centroCosto]')[0].getStore().data.items[i].data.montos_int;
            var seleccionado = Ext.ComponentQuery.query('[itemId=grid_centroCosto]')[0].getStore().data.items[i];
            Ext.ComponentQuery.query('[itemId=grid_centroCosto]')[0].getStore().remove(seleccionado);

        }
    }


    //SE RESTA PORCENTAJE DISTRIBUCION QUE SE ELIMINO
    var pocentaje_dist = Ext.ComponentQuery.query('numberfield[name=txt_total_distribucion]')[0].getValue();

    var pocentaje_dist =  pocentaje_dist - form_48.app.porcentaje_distrib;

    Ext.ComponentQuery.query('numberfield[name=txt_total_distribucion]')[0].setValue(pocentaje_dist);

    //SE RESTA EL MONTO QUE SE ELIMINO
    var monto_actual = form_48.app.getController('FormateoNumero').miles_int(Ext.ComponentQuery.query('textfield[name=txt_total_monto]')[0].getValue());

    var monto_final = monto_actual - monto_origen;
    var monto_final_miles = form_48.app.getController('FormateoNumero').int_miles(monto_final);

    Ext.ComponentQuery.query('textfield[name=txt_total_monto]')[0].setValue(monto_final_miles);




}

Your view:

            {
                xtype: 'combobox',
                width: 408,
                fieldLabel: 'Unidad',
                labelWidth: 110,
                name: 'cmb_nuevoUnidad',
                readOnly: false,
                allowBlank: false,
                blankText: 'Campo obligatorio',
                emptyText: 'Seleccione...',
                displayField: 'unidad_nombre',
                queryMode: 'local',
                store: 'sto_unidades',
                valueField: 'unidad_codigo',
                listeners: {
                    select: 'onUnidadSelect'
                }
            }

Your store:

Ext.define('form_48.store.sto_unidades', {
extend: 'Ext.data.Store',

requires: [
    'form_48.model.mdl_unidades',
    'Ext.data.proxy.Ajax',
    'Ext.data.reader.Json'
],

constructor: function(cfg) {
    var me = this;
    cfg = cfg || {};
    me.callParent([Ext.apply({
        storeId: 'sto_unidades',
        autoLoad: true,
        model: 'form_48.model.mdl_unidades',
        proxy: {
            type: 'ajax',
            extraParams: {
                combo: 'unidades'
            },
            url: 'json/seccion1.php',
            actionMethods: {
                create: 'POST',
                read: 'POST',
                update: 'POST',
                destroy: 'POST'
            },
            reader: {
                type: 'json',
                rootProperty: 'root'
            }
        }
    }, cfg)]);
}
});

Now the Textfield

onFacultadKeyup: function(textfield, e, eOpts) {
    textfield.setValue(textfield.getValue().toUpperCase());
},

Your view:

{
                xtype: 'textfield',
                anchor: '100%',
                fieldLabel: 'Dirección/Facultad',
                labelWidth: 110,
                name: 'txt_direccionFacultad',
                enableKeyEvents: true,
                listeners: {
                    keyup: 'onFacultadKeyup'
                }
            }

I do not know if a store should be made to the texfield or not, but the Units store connects to the section1.php that contains the SQL query

I hope I can be clearer there.

    
asked by user3565613 06.06.2017 в 02:32
source

1 answer

0

If I understand well what you want to do is: fill textfield based on what you selected in combobox you could do it in the following simple way:

First of all we go with the definition of the combo:

tuCombobox = {
        xtype: "combobox",
        itemId: 'myId',
        fieldLabel:'etiqueta',
        queryMode: "local",
        store: myStore,
        displayField: 'LABEL',  //el valor a mostrar de cara al usuario
        valueField: 'VALUE', //el valor de los datos que manejarás
        listeners: {
            change: this.onUnidadSelect,
            scope: this
        }
    };

Keep in mind that all combobox is associated with a store which, in turn, is associated with a data model with which you will load them. As you can see, we add a listener and with scope we passed the context.

Now define the onUnitySelect function which will receive the new value selected in the combobox:

onUnidadSelect: function (combobox, newValue) {
    // ....
    Ext.getCmp('myId').setValue(newValue);
}

Inside this function is where you can apply the new value of the combo ( newValue ) to the textfield you want with the setValue () . Which previously you must have instantiated.


Although it would have been much easier, if you put the definition of your combobox and that of your textfield (at least). We do not need (nor want or intend to) see the complete code of your entire application, only the part of the code that exemplifies your problem / doubt / query.

    
answered by 06.06.2017 / 12:56
source