PDA

View Full Version : Trying to create dynamic form



wallynm
17 Jan 2012, 6:38 AM
Hey guys, on my system i have this code:



xtype:'combobox',
store: 'Financeiro.ClienteFornecedor.ComboTipoPessoa',
queryMode: 'local',
displayField: 'nome',
valueField: 'val',
fieldLabel: 'Pessoa',
name:'tipo',
listeners: {


// Todos os momentos em que o usuario trocar a opcao de tipo de pessoa,
// os formularios do campo serao exibidos/escondidos, de acordo com o tipo da pessoa
change: function(f, val) {


// Captura todos fieldsets dentro do form especifico
var fieldset = Ext.ComponentQuery.query('ClienteForm fieldset');
for(var i in fieldset){
if(fieldset[i].tipoPessoa != undefined){
if(fieldset[i].tipoPessoa == val){
fieldset[i].show()
} else {
fieldset[i].hide()
}
}
}
}
}


It's a combobox creation, on the code, it is inside a form.

My problem here is that i would like to create another file with this combobox config, them when i need to use it just call he file refference, today i'm doing it with MVC archteture, but i would like to do it with other components too...

I think it should work:


Ext.define('myapp.MyFolder.Structure', {
extend:'combobox',
//rest of the code...
})

But i don't know how i would use/call it inside my form definition...

kskrumpet
17 Jan 2012, 6:51 AM
This should work:


xtype: 'form',
items: [{
... some items ...
}, new myapp.MyFolder.Structure(), {
... some more items ...
}]

The Ext.define simply creates a class, so calling new will create a new instance of that class. Make sure you don't define an id in the class though, as each instance will have the same id.

wallynm
17 Jan 2012, 6:59 AM
This should work:


xtype: 'form',
items: [{
... some items ...
}, new myapp.MyFolder.Structure(), {
... some more items ...
}]

The Ext.define simply creates a class, so calling new will create a new instance of that class. Make sure you don't define an id in the class though, as each instance will have the same id.

Awesome!!! I had see it before but i couldn't fint it again, thanks @kskrumpet (http://www.sencha.com/forum/member.php?124711-kskrumpet) , i just changed it to the new sintax to Ext4 convenience... Ext.create('MyApp.views.UsersGridPanel')...

wallynm
17 Jan 2012, 10:45 PM
@mitchellsimoens (http://www.sencha.com/forum/member.php?22216-mitchellsimoens) - Could you unmark the best answer?
I had replied it, but i'm still can't make it work, as Ext.create return error message....

Crhome:
c is not a constructor
...instantiators[length] = new Function('c', 'a', 'return new c('+args.join(',')+'...

Firefox:
Uncaught TypeError: object is not a function

I had created another pos, to try to solve this problem, the links is this:
http://www.sencha.com/forum/showthread.php?174994-Ext.create-on-store-returning-error

kskrumpet
18 Jan 2012, 12:12 AM
Sorry to hear you're having problems. I tried with both new and Ext.create() - both work for me.

kskrumpet
18 Jan 2012, 12:20 AM
I just looked at your original code again and noticed one difference between your code and my test case - I used:
extend: 'Ext.form.field.ComboBox'
You used:
extend: 'combobox'

If I change my code to use combobox, I get the same error. Please use the full class name.

wallynm
18 Jan 2012, 12:43 AM
Still can't make it work...
If i define a class like this:

Ext.define('myapp.MyFolder.Structure', {
...code
})

i should call it on my form like this:

Ext.create('myapp.MyFolder.Structure');


If yes, there's something wrong with my code, because i'm still gettin same error. Anyway, thanks by trying to help!

kskrumpet
18 Jan 2012, 12:53 AM
I guess you didn't see my follow up - it's the extend: that's the problem. Use:
extend: 'Ext.form.field.ComboBox'

Not:
extend: 'combobox'

wallynm
18 Jan 2012, 5:27 AM
I guess you didn't see my follow up - it's the extend: that's the problem. Use:
extend: 'Ext.form.field.ComboBox'

Not:
extend: 'combobox'

That's why it is strange, i did it... :(