1. #1
    Sencha User
    Join Date
    Jun 2011
    Posts
    147
    Answers
    5
    Vote Rating
    2
    rafaelrp is on a distinguished road

      0  

    Default Answered: How to get text in a form with ComponentQuery in a controller [MVC]

    Answered: How to get text in a form with ComponentQuery in a controller [MVC]


    Correcting the title: How to get textfield in a form with ComponentQuery in a controller [MVC]

    Hello, i have a view with a form,

    i need to get a textfield in that form and in the controller a need to set a value to this textfield, and i have a store that have the data i want to set in the textfield.

    When i select a value in the combo Serv i need to set a value to the textfield Name, setting the Name in the store Serv that was loaded when i selected a value in Cli.

    Code:
    Ext.define('Pagamator.view.lancamentos.Create', {
        
        extend: 'Ext.window.Window',
        alias: 'widget.lancamentosCreate',
        
        title: 'Add',
        width: 450,
        modal: true,
        resizable: false,
            
        autoShow: true,
        
        initComponent: function(){
            this.items = [
                 {
                     xtype: 'form',
                     layout: 'form',
                     bodyPadding: 5,
                     items: [
                            {
                             xtype: 'combo',
                             name: 'cli',
                             store: 'Cli',
                             queryMode: 'local',
                             fieldLabel: 'Cli',
                             valueField: 'CliId',
                             displayField: 'name',
                             allowBlank: false
                         },
                           {
                             xtype: 'combo',
                             name: 'serv',
                             store: 'Qtd',
                             queryMode: 'local',
                             fieldLabel: 'Serv',
                             valueField: 'QtdId',
                             displayField: 'Qtd',
                             allowBlank: false
                         }
    
    
                         {
                             xtype: 'textfield',
                                   name: 'name'
                         }
    .....

    Controller function
    Code:
    getServ: function(combo, newValue){
            var win = Ext.ComponentManager.get('widget.lancamentosCreate');
            
            console.log(win);
            
            this.getQuantidadeSemanalClienteStore().load({params: {clienteId: newValue}});
        }
    store:
    Code:
    Ext.define('Pagamator.store.Qtd', {
        extend: 'Ext.data.Store',
        model: 'Pagamator.model.Qtd',
        autoLoad: false,
        
        proxy: {
            type: 'ajax',
            url: 'data/QtdList.php',
            reader: {
                type: 'json',
                //root: 'data',
                successProperty: 'success'
            }
        }
    });

    UPDATE
    ----------------------------------------

    I managed to catch the numberfield with this code
    Code:
    var win = combo.up('window');
    		var form = win.down('form');
    		var numberfield = form.query('textfield[name=valor]')[0];
    Now what i need is to set the numberfield value with a field that the store Qtd loads.. there a way i can do this?

    Thanks!

  2. If you're looking to set the textfield's value with that of the combobox you should be able to first get the value from the combo using getValue() and set the value of the textfield using its setValue() method.

    Also, for convenience instead of using:
    var numberfield = form.query('textfield[name=valor]')[0];
    you may be able to use:
    var numberfield = form.down('[name=valor]');

    Not much savings, but down() finds the first matching component so you don't have to specify [0]. This would get the first component with property name with value valor, so if you have several of those you may still need the textfield in front of it like in your current code.

  3. #2
    Sencha - Support Team slemmon's Avatar
    Join Date
    Mar 2009
    Location
    Boise, ID
    Posts
    4,770
    Answers
    355
    Vote Rating
    165
    slemmon is a splendid one to behold slemmon is a splendid one to behold slemmon is a splendid one to behold slemmon is a splendid one to behold slemmon is a splendid one to behold slemmon is a splendid one to behold slemmon is a splendid one to behold

      1  

    Default


    If you're looking to set the textfield's value with that of the combobox you should be able to first get the value from the combo using getValue() and set the value of the textfield using its setValue() method.

    Also, for convenience instead of using:
    var numberfield = form.query('textfield[name=valor]')[0];
    you may be able to use:
    var numberfield = form.down('[name=valor]');

    Not much savings, but down() finds the first matching component so you don't have to specify [0]. This would get the first component with property name with value valor, so if you have several of those you may still need the textfield in front of it like in your current code.

  4. #3
    Sencha User
    Join Date
    Jun 2011
    Posts
    147
    Answers
    5
    Vote Rating
    2
    rafaelrp is on a distinguished road

      0  

    Default


    I use this function to set the value form a ajax store load.

    Code:
    this.getQuantidadeSemanalClienteStore().load({
    			params: {clienteId: newValue},
    			callback: function(store, records) {
    				var rec = records.response.responseText;
    				var valor = Ext.JSON.decode(rec)[0].valor
    				numberfield.setValue(valor);
    			}
    		});
    And i'll use the .down function.

    Thanks!

Thread Participants: 1

film izle

hd film izle

film sitesi

takipci kazanma sitesi

takipci kazanma sitesi

güzel olan herşey

takipci alma sitesi

komik eğlenceli videolar