PDA

View Full Version : decoding Html chars



raj_plays
20 Aug 2012, 12:49 AM
Hi,
My XML store has a record with a field like...
<Title>&apos;TIL MY LAST DAY</Title>
When I render it in a grid column, it decodes the string automatically and displays
'TIL MY LAST DAY
but when I render the same field in a textbox in a form, it displays the encoded string.
I tried..


{xtype: 'textfield', id: 'title', fieldLabel: 'Title', value: Ext.util.Format.htmlDecode(song_record.data.Title)}

It did not work. I am using Ext 3.3.1.
Please help.

sword-it
20 Aug 2012, 3:34 AM
Hi raj,

If you look at the list of HTML 4 character entities, (http://www.w3.org/TR/html4/sgml/entities.html)&apos; isn't on it. That's why it shouldn't be used. From C.16. The Named Character Reference ' (http://www.w3.org/TR/xhtml1/#C_16) , you should therefore use ' instead of &apos; to work as expected.

raj_plays
20 Aug 2012, 5:32 AM
Thank you, sword-it.

raj_plays
20 Aug 2012, 10:38 PM
Hi,
Even then it does not work.
I did this in my Record config


var song = Ext.data.Record.create([{
name: 'Title',
type: 'string',
convert: function (v, rec) {
return v.indexOf('&apos;') != -1 ? v.replace('&apos;', '&#39;') : v;
}
}, {
name: 'Artist',
type: 'string'
}
]);


Then in another function, I did Ext.util.Format.htmlDecode(song_record.data.Title).
It showed the encoded string.

In fact the code below outputs '&#39;'
alert(Ext.util.Format.htmlDecode('&#39;'));

Please help