PDA

View Full Version : problem display'n information on a textfield



rrochap
27 Aug 2008, 11:43 AM
I store informacion on my database, in using mysql i bring some information to my form using json. on the data base for example is stored 'en' but on the form appears 'en&#039 when i show it on a textfield or a textarea,
how can i fix that?

rrochap
5 Sep 2008, 6:28 AM
any idea????

Darklight
5 Sep 2008, 6:31 AM
&#039 ; is the ' sign. your backend probably returns it like this, so you should look for the fix there. check with FireBug what is delivered via json

Condor
5 Sep 2008, 6:36 AM
You should post the source (that you already PM'ed me).

Also, post the data that is actually received from the server (use Firebug's Net tab).

rrochap
5 Sep 2008, 6:42 AM
hey men thnks 4 ur help..
now i check the json response and ur right, it comes with ' but.. when i show it in the grid it shows ( ' ) thats ok.... but when it shows on a text field, shows ' .. i think. the problem is the way that the information is decode by the grid or texfield is different.. i dont know...
:(

rrochap
5 Sep 2008, 6:46 AM
Json..


{"results":[{"id_":"'A'","nom":"'B'","tip":"'C'","des":"'D'","sql":"'E'"}]}

hey, in this part instead of ( ' ) the json response is with ( & 0 3 9 ; ) but when it paste it and show it.. just transform it..

Code...


var form = new Ext.FormPanel({
region:'center',
el:'main-form',
width:'100%',
bodyStyle:'padding:5px 5px 0',
labelWidth:75,
labelAlign:'right',
reader: new Ext.data.JsonReader({
root:'results',
id: 'id_',
fields: ['id_', 'nom', 'tip', 'des', 'sql']
}, [
{name:'query.id', mapping:'id_'},
{name:'query.nombre', mapping:'nom'},
{name:'query.tipo', mapping:'tip'},
{name:'query.descripcion', mapping:'des'},
{name:'query.sql', mapping:'sql'},
]),
layout:'form',
defaults:{ width:250 },
items: [{
xtype:'hidden',
name:'query.id'
},frm_tipos,
{
xtype:'textfield',
fieldLabel:"Nombre",
name:'query.nombre',
allowBlank:false,
maxLength:20
},{
xtype:'textarea',
fieldLabel:"Descripcion",
name:'query.descripcion',
allowBlank:false,
maxLength:150
},{
xtype:'textarea',
fieldLabel:"Query",
allowBlank:false,
height:200,
width:400,
name:'query.sql'
}]

Darklight
5 Sep 2008, 6:58 AM
you could try Ext.util.Format.htmlDecode()

Condor
5 Sep 2008, 7:07 AM
So your server is already sending the & #039; ?

In that case the JsonReader needs to decode the values:

...
[
{name:'query.id', mapping:'id_', convert: decode039},
{name:'query.nombre', mapping:'nom', convert: decode039},
{name:'query.tipo', mapping:'tip', convert: decode039},
{name:'query.descripcion', mapping:'des', convert: decode039},
{name:'query.sql', mapping:'sql', convert: decode039}
]
...
with

function decode039(v) {
return !v ? v : String(v).replace(/& #039;/g, "'");
}

ps. Remove the space between & and #039.

rrochap
5 Sep 2008, 7:11 AM
ok .. but for each field of my form???? i think its a little. difficult.. cause i have a lot of forms... but.. i still don't understand.. why works with grids and not with textfields, textareas and comboxes..
there's not a better way to do that?

Darklight
5 Sep 2008, 7:15 AM
maybe the grid has htmldecode built in. the easiest way would still be to have your backend send it correctly ;)

Condor
5 Sep 2008, 7:16 AM
Wouldn't it be easier to fix the data generation on the server? It is generating HTML instead of plain text.

rrochap
5 Sep 2008, 7:17 AM
thnks.. condor.. but.. your solution is good just for the # & 0 3 9 problem.. but when i use ( " ) it shows # & 0 3 8 and other character .. acorddin that i will have to validate. all characters...

jsakalos
6 Sep 2008, 10:58 PM
There must be something deadly wrong with your server setup. I've never run into anything similar with properly configured Apache 2 + PHP 5 + json_encode. Also, I just cannot believe that you really want to display 'A' in a field instead of plain A.

rrochap
8 Sep 2008, 7:06 AM
well thanks... for your suggestion..
what i try to do is a Query editor.. for my data base. and i really need to show the quotes ( " and ' ) thats the main reason... and well.. i dont think my server is DEADLY WRONG cause. the quotes works with grids but not with textfield.. and textareas.. and i use the same json for that.. just to test and works fine with grids. but fails with the other ones..

Condor
8 Sep 2008, 7:09 AM
Maybe 'DEADLY' is a bit overdone, but I still think your server should send plain quotes and not HTML escaped ones.

What kind of backend are you using to generate the data?

jsakalos
8 Sep 2008, 11:40 AM
The easiest test you can do is to create a file with json content (e.g. response.html) and to point url to it. This way you bypass any server processing that may be done but server just returns plain content of response.html file.

rrochap
30 Sep 2008, 11:43 AM
thnks... a lot.. i found the problem.. i was.. some missing tags on my json.. ;)