PDA

View Full Version : [CLOSED][3.0rc2] Ext.form.TextField -> minLength, allowBlank and spaces



tobiu
21 Jun 2009, 7:59 AM
Ext version tested:



Ext 3.0-rc2





Browser versions tested against:



____

FF3 (firebug 1.3.0.10 installed)





Operating System:



________

WinXP Pro





Description:



This "unexpected behaviour" occurs also in older versions. example: you have a field with the allowBlank:false config.typing a space will make the field valid. when you have minLength:3 in the config, typing space 3 times will also make the field valid. this is more an issue of form.field, since it happens in all subclasses (numberField, comboBox etc). It should be quite easy to fix: just trim the value (or at least ltrim) and then check it like it is done now.



kind regards, tobiu

evant
21 Jun 2009, 8:02 AM
You're assuming that spaces don't count as characters. Is " a" invalid? Is " a " invalid? is "a " invalid?

I don't really think this is a bug. If you want to implement that behaviour in your app that's fine, but it doesn't really apply to all cases.

Condor
21 Jun 2009, 9:00 AM
Note:
You can automatically trim the entered value by using:

stripCharsRe: /(^\s+|\s+$)/g
(but you might want to increase the validationDelay, otherwise you can't enter a space while typing)

tobiu
22 Jun 2009, 12:34 AM
hi you two,

@evant: considering allowBlank : false the 3 inputs " a", " a " and "a " are all valid. considering the case with minLength : 3, none of them would be. do you have 1 single case, where leading (or ending) spaces do make sense? i found none, that's the reason why i suggested to change it.

@condor: i do not want to directly change the input of the user (at least not on the client-side. before inserting into a db, this is different). the idea is, to use the trimmed input for validation.

if i find some time and a good idea how to implement it, i will post it here.

kind regards, tobiu

valcamo
23 Jun 2009, 3:45 AM
@tobiu:
May I suggest this workaround?



var textfield = Ext.getCmp('the-id');

textfield.on('blur', trimValue);
// you can also add the listener using config

function trimValue() {
var value = this.getRawValue();
var trimmed = value.trim();
if(value !== trimmed) {
this.setRawValue(trimmed);
this.validate();
}
}


or this one:



textfield.processValue = function(value) { return value.trim(); }

mjlecomte
23 Jun 2009, 7:25 AM
hi you two,

@evant: considering allowBlank : false the 3 inputs " a", " a " and "a " are all valid. considering the case with minLength : 3, none of them would be. do you have 1 single case, where leading (or ending) spaces do make sense? i found none, that's the reason why i suggested to change it.

@condor: i do not want to directly change the input of the user (at least not on the client-side. before inserting into a db, this is different). the idea is, to use the trimmed input for validation.

if i find some time and a good idea how to implement it, i will post it here.

kind regards, tobiu

I'm not sure, but you appear to be drawing a relation between "allowBlank" and "whether blank spaces should be allowed". "allowBlank" is akin to saying "allow the textfield to be empty".

Why would you only change the input at the server? From the user perspective I'd want to see what was actually saved.

DeathPhoenix
17 Mar 2010, 6:39 AM
I know this bug is closed, But I want to make this thing CLEAR. First, the definition of blank (open your dictionary plz...) is about alphabetic spaces... Did you know? Blank as nothing to do with "empty". AllowBlank=false means : allow nothing or spaces = false. AllowEmpty is what you have here!

Also, in GUI validation, this type of string " " is a common type of errors committed by programmers community. They forgot to "trim" there field to validate if there is actually text or not! ...

Also, (other point of view) do the next line contain text?

In your validation, yes... for 99% of ppl, it doesn't. Do the next line contain text?
think about it...
I think this is clear that the next line contained text... and is not blank.

Should be reopened or the function should be renamed.