View Full Version : How to get text in a form with ComponentQuery in a controller [MVC]

24 Apr 2013, 5:33 AM
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.

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

getServ: function(combo, newValue){
var win = Ext.ComponentManager.get('widget.lancamentosCreate');


this.getQuantidadeSemanalClienteStore().load({params: {clienteId: newValue}});


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'


I managed to catch the numberfield with this 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! ~o)

25 Apr 2013, 6:57 PM
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.

26 Apr 2013, 10:05 AM
I use this function to set the value form a ajax store load.

params: {clienteId: newValue},
callback: function(store, records) {
var rec = records.response.responseText;
var valor = Ext.JSON.decode(rec)[0].valor

And i'll use the .down function.

Thanks! ~o)