PDA

View Full Version : Load JSON store value into textfield



jwdepetro
1 Apr 2014, 7:38 AM
I am fairly new to ExtJS and need some help with this one. I have searched the existing questions and could not get anywhere with those.

I have a basic textfield that I need to autopopulate with a specific value from my JSON store.

JSON Store:

ticketInfoStore = new Ext.data.JsonStore({
url: '../Events.php?task=getInformation&event_id=',
root: 'data',
idProperty: 'id',
fields: ['id','tkt_title1_c','tkt_title2_c','tkt_perf1_c','tkt_perf2_c','tkt_venue1_c','tkt_venue2_c']
});


Here is my textfield:

new Ext.form.TextField({
name: 'ticket_title2',
width:170,
fieldLabel: 'Ticket Title 2',
maxLength: 50

}),


This field needs to have the 'tkt_title2_c' value auto populated in it. Not sure how to do this. Any help is appreciated.

benzo11
3 Apr 2014, 9:04 AM
Hello there, check you dont have parameter "name" which is main thing to use JsonStore, must be like:



var store= new Ext.data.JsonStore({
url:'<?php echo $ajax;?>', //ajax file with defined actions
id:'storeId',
root:'rows',
baseParams:{
action:'loadUsersData' //action called from ajax
},
fields:[
{name: 'id_user', type: "int"},
{name:'name',type:'string'},
{name:'surname',type:'string'},

]
});
store.load();

and in panel I got items

items:[{ xtype:'textfield',
fieldLabel:'Name',
width:150,
name:'name',
id:'name'
}

jwdepetro
3 Apr 2014, 1:07 PM
Thanks for the response.

I've tried this suggestion and am still not getting any field population from the JSON store.

benzo11
3 Apr 2014, 1:27 PM
Can you post your ajax function where you have action to retrieve data from db?

willigogs
3 Apr 2014, 3:17 PM
If you need the textField to be populated with the tkt_title2_c value, then give your textField the name of tkt_title2_c, and do something like:


Ext.getCmp('your-form-id').getForm().loadRecord(pass_in_the_record_here);

Alternatively you could grab the value you wish to populate the textField with, then use the textfield's setValue() method to populate it.