PDA

View Full Version : htmlDecode for text fields and combos.



masood
19 Aug 2013, 6:23 PM
I am getting html encoded data back from the server. Where is the best place to apply Ext.String.htmlDecode() for text fields?
Is doing the following a safe option?


Ext.define('mypatches.form.field.Text', {
override: 'Ext.form.field.Text',
setValue: function (value) {
value = Ext.String.htmlDecode(value);
return this.callParent(arguments);
}
});

Combo's seem to do half the html decoding already (see picture) where should the override be for a combo?
I have gone through the forum and found this post (http://www.sencha.com/forum/showthread.php?43841-ExtJS-lack-of-html-encoding/page3) but it has not worked.
Thanks
Masood

45430

masood
19 Aug 2013, 7:47 PM
Did some more digging and this seems to work for both combos and text fields.
But still would be great to hear from someone more knowledgeable to say if this is fine or not...


Ext.define('mypatches.form.field.Text', {
override: 'Ext.form.field.Text',
transformRawValue: function(value) {
return Ext.String.htmlDecode(value);
}
});

Gary Schlosberg
22 Aug 2013, 3:53 PM
What you are doing seems reasonable to me, though someone with more experience may chime in to enlighten.

masood
22 Aug 2013, 6:18 PM
Thanks Gary. I had to make the following change for combos, otherwise the value submitted is only the display text and not the id.



//For combo
Ext.define('mypatches.form.field.ComboBox', {
override: 'Ext.form.field.ComboBox',
initComponent: function () {
this.displayTpl = new Ext.XTemplate(
'<tpl for=".">' +
'{[Ext.String.htmlDecode(typeof values === "string" ? values : values["' + this.displayField + '"])]}' +
'<tpl if="xindex < xcount">' + this.delimiter + '</tpl>' +
'</tpl>'
);
this.callParent(arguments);
}
});

//For text fields
Ext.define('mypatches.form.field.Text', {
override: 'Ext.form.field.Text',
transformRawValue: function(value) {
return Ext.String.htmlDecode(value);
}
});

Gary Schlosberg
23 Aug 2013, 9:12 AM
Thanks for posting your solution for the community.