PDA

View Full Version : Question about Ext.form.field.TextArea and its stripReturns



sneakyfildy
24 Jul 2012, 12:06 AM
http://docs.sencha.com/ext-js/4-1/#!/api/Ext.form.field.TextArea

stripReturns: function(value){ if (value) { value = value.replace(this.returnRe, ''); } return value; } (http://docs.sencha.com/ext-js/4-1/#!/api/Ext.form.field.TextArea)When value in textarea is number exception is thrown and all fails.
Wheres the hidden reason for doing .replace on any value type? Why there's no safety blocks? Textarea is only for text input?

friend
24 Jul 2012, 9:30 AM
From looking at the source of Ext.form.field.TextArea (http://docs.sencha.com/ext-js/4-1/source/TextArea2.html#Ext-form-field-TextArea), it appears that stripReturns is intended to remove any carriage returns in the entered text, where the regex expression /\r/ is used to indicate a carriage return.

I coded a TextArea component and typed in numbers only, then a few carriage returns and it seems to be working correctly for me (ExtJs v4.1.1).

When do you encounter an error in your TextArea field? On blur? And are you doing any custom validation on this field?

newtoyou
18 Sep 2013, 8:12 AM
This is definitely still an issue in 4.2 (build aed16176e68b5e8aa1433452b12805c0ad913836). The issue is not what happens if there is a numeric value with carriage returns to be stripped. The issue is if the value is a strictly numeric value. StripReturns is still called and attempts to call .replace against a numeric type. That's what blows up. We need a fix for this ASAP. :((

sneakyfildy
18 Sep 2013, 10:17 PM
This is definitely still an issue in 4.2 (build aed16176e68b5e8aa1433452b12805c0ad913836). The issue is not what happens if there is a numeric value with carriage returns to be stripped. The issue is if the value is a strictly numeric value. StripReturns is still called and attempts to call .replace against a numeric type. That's what blows up. We need a fix for this ASAP. :((

Yeah. That;s true. I forgot to add that number + any string, even carriage return, lol, is string. Only number fails.

evant
18 Sep 2013, 10:25 PM
The issue is resolved in 4.2.1, the code is:



stripReturns: function(value){
if (value && typeof value === 'string') {
value = value.replace(this.returnRe, '');
}
return value;
}

sneakyfildy
18 Sep 2013, 10:36 PM
The issue is resolved in 4.2.1, the code is:



stripReturns: function(value){
if (value && typeof value === 'string') {
value = value.replace(this.returnRe, '');
}
return value;
}


That's cool. Thank you very much. I'm still using 4.2 Project is too complex to apply every update =))