PDA

View Full Version : How to filll a textfield with data from a JsonReader datastore



icarey
28 Mar 2010, 1:47 AM
Hello,
I would like to be able to fill a textfield in a formpanel with data from a database.
I have a data store working where I have obtained an ID from a table. Now I want to display this ID in a textfield. Is this possible or do I have to do it another way?

********************************************************
var idstore = new Ext.data.Store({
reader: new Ext.data.JsonReader({
fields: ['ID'],
root: 'idrows'
}),
proxy: new Ext.data.HttpProxy({
url: 'iddata.php'
}),
autoLoad: true
});

********************************************************
FormPanel

{xtype: 'textfield',
fieldLabel: 'Event Number',
name: 'eventid',
anchor: '100%'}


Thanks,
Ivan

evant
28 Mar 2010, 1:56 AM
Are you only retrieving a single number from a server? If so, that's fairly overkill.



Ext.Ajax.request({
url: 'foo',
success: function(response){
myField.setValue(response.responseText);
}
});

icarey
29 Mar 2010, 2:06 AM
Hello Evan
Thank you
I am new at JavaScript and have been looking for a solution but I am at loss as how to implement to your solution. I think I have the response from the server ok because if i put a message box in your code I get the value from the server which at the moment is 7

Ext.Ajax.request({
url: 'medlogid.php',
method: 'get',
success: function(response){
myField.setValue(response.responseText);
Ext.MessageBox.alert('Success', 'Data return from the server: '+ response.responseText);
}
});

How do i get this value into the text field?
if I use eventid.myField.setValue(response.responseText);
nothing happens, also I am not sure where I should place the Ext.Ajax.request

Thank you,
Ivan

Animal
29 Mar 2010, 2:54 AM
Have you debugged?

icarey
29 Mar 2010, 3:00 AM
In firebug it says eventid not defined

Condor
29 Mar 2010, 3:05 AM
Where did you define an object 'eventid'?

I think you want:

Ext.getCmp('id-of-eventid-field').setValue(response.responseText);

Animal
29 Mar 2010, 3:05 AM
So. Have you debugged it then?

"eventid not defined" is a bug.

icarey
29 Mar 2010, 3:09 AM
eventid is defined in the FormPanel

{xtype: 'textfield',
fieldLabel: 'Event Number',
name: 'eventid',
anchor: '100%'}

sorry animal I dont know how to debug in javascript

Condor
29 Mar 2010, 3:29 AM
How can you even develop javascript application without knowing how to debug it? (read this (http://getfirebug.com/javascript)).

In the fragment you posted you only define a config object for a textfield named 'eventid'. This will NOT create an object 'eventid'!

The TextField that is created from this config object can be located with:

var eventid = formPanel.getForm().findField('eventid');
(assuming you do have a reference to the formpanel)
or

var eventid = Ext.getCmp('id-of-eventid-field');
(assuming you configure the field with a unique id 'id-of-eventid-field')

icarey
31 Mar 2010, 2:46 AM
I have now looked at how to use firebird for debugging

some of the answers give snippets without explaining things to help someone like me that is very new to JavaScript. We all have to start somewhere.

Thanks Evan for your code
Ext.Ajax.request({
url: 'foo',
success: function(response){
myField.setValue(response.responseText);
}
});It finally dawned on me that I needed to define an ID: 'eventid'
as I thought this was name: 'eventid'

{xtype: 'textfield',
fieldLabel: 'Event Number',
id: 'eventid',
name: 'eventid',
anchor: '100%'}