PDA

View Full Version : set value to combo on textfield onBlur function



honeyandbee
19 Oct 2012, 10:52 PM
Hi everyone,
this is my first post here and i am kinda new of extjs. What i want to set a value to a combo onBlur function on a text field but i am not being able to do it . I am using mvc with groovy. Can anyone please help me ?! here is my code below :

the text field action calling here :


{
xtype:'textfield',
fieldLabel: 'Member No',
name: 'memberno',
anchor:'100%',
id:'id5',
action:'memberno'
}

combo declare is here :


{
xtype:'combo',
id:'id7',
fieldLabel: 'Branch',
forceSelection:true,
store:'Branchs',
emptyText:'Select Branch...',
triggerAction: 'all',
editable:false,
displayField:'branchname',
valueField:'id',
mode: 'remote',
name: 'branch',
margin: '0 0 0 0',
anchor:'100%'
}

and the function is here :


function () {
var a = Ext.getCmp('id5').getValue();
if(a != ""){
var model = Ext.create('Ext4Example.model.Account',{
//id:a
});
Ext4Example.model.Account.load(a, {
success: function(model) {
if(model != null){
var xmno = model.get('exmemberno');
var brn = model.get('branch');
var slt = model.get('salutation');
var fname = model.get('fullname');
var nname = model.get('nickname');
var accno = model.get('id');
Ext.getCmp('id1').setValue(accno);
Ext.getCmp('id6').setValue(xmno);
Ext.getCmp('id7').setValue(brn);
Ext.getCmp('id8').setValue(slt);
Ext.getCmp('id9').setValue(fname);
Ext.getCmp('id10').setValue(nname);
console.log(xmno,brn,slt,fname,nname);
}
console.log('loaded');
},
failure: function(){
console.log('Unable to load');
}
});
}else{
Ext.Msg.alert("Alert","Please insert Member no");
}
}

skirtle
20 Oct 2012, 10:57 AM
Please use [CODE] tags when posting code so it's easier to read. I've added them to your post.

My first observation is that you're using a setting from ExtJS 3 that no longer exists in ExtJS 4:


mode: 'remote',

In ExtJS 4 this setting is called queryMode. This setting is a common source of confusion as local/remote do not refer to where the data originates in the way you might expect. It actually refers to where the data is filtered. If you're using distinct fields for valueField and displayField then you almost certainly want:


queryMode: 'local'

For more information on this setting see:

http://docs.sencha.com/ext-js/4-1/#!/api/Ext.form.field.ComboBox-cfg-queryMode
http://skirtlesden.com/articles/extjs-comboboxes-part-2

The next thing I notice is that you're using static ids. e.g.:


id: 'id5'

I highly recommend that you avoid using them, they're fine for tiny applications or demos but for any real application I'd stay well clear. Likewise Ext.getCmp is generally to be avoided.

For setting a large number of form field values based on a record you may find it neater to use loadRecord:

http://docs.sencha.com/ext-js/4-1/#!/api/Ext.form.Panel-method-loadRecord

Essentially loadRecord just iterates through the record's fields and looks for form fields with the same name. It then calls setValue with the appropriate value.

However, none of this really explains why your code isn't working.

Is your function definitely being called? You haven't explained how it gets invoked so it's difficult to tell. Try adding some console logging to make sure it gets called. Likewise do you see the Ajax request for loading the model in the debugger? Finally, is the success method being called, again easily verified with a bit of console logging or a breakpoint.

If everything is being called then the next potential problem is setting the values correctly. For a combobox with a valueField you need to ensure the values you use with setValue match the valueField, not the displayField. So in your case you'd need to use values that match the id field of the records in your Branchs store.

More information on exactly which bit isn't working would make it much easier to help you.

honeyandbee
20 Oct 2012, 7:57 PM
Thank you so much for replying and for suggesting me

The fact is that When I load the combo value for branch it comes from another store. And I have the field in the same form memberno which is calling the funcion to load the value in combo from another table where i have saved other value include this branchname . And my function is being called and derived the following information as follows :


1 6 1 Md. Sumon Bappi Bappi

Up here 6 is the id for branchname and when i write setRawValue() then it sets the id but when i write setValue() it doesn't work Now what should I do to show the branchname instead of id I am so confused

honeyandbee
22 Oct 2012, 3:02 AM
Hi skirtle anyhow I have solved the problem. I don't know that is it perfect or not but I am getting my desire result. Just I had to do work in the get() portion of rest method in groovy controller. I just added other domain's field value there and so did in the corresponding model. And finally set the value in the components from controller. But one thing I want to learn that you said not to use Ext.getCmp() so what should I use can you seggest me the best ?!