X-Git-Url: http://git.roojs.org/?a=blobdiff_plain;f=Roo%2Fform%2FTextField.js;h=20a8c7dd0f13cc57b3a1c0d6bb5aba87b7fa3c05;hb=16d585588738895fd73db1cc2cf3754144012aab;hp=8b1090bd731ca1d9697a929043f5fc1fb315e064;hpb=c2325384138e7738464ef2149873f82efff06e45;p=roojs1 diff --git a/Roo/form/TextField.js b/Roo/form/TextField.js index 8b1090bd73..20a8c7dd0f 100644 --- a/Roo/form/TextField.js +++ b/Roo/form/TextField.js @@ -83,6 +83,10 @@ Roo.extend(Roo.form.TextField, Roo.form.Field, { * @cfg {Boolean} selectOnFocus True to automatically select any existing field text when the field receives input focus (defaults to false) */ selectOnFocus : false, + /** + * @cfg {Boolean} allowLeadingSpace True to prevent the stripping of leading white space + */ + allowLeadingSpace : false, /** * @cfg {String} blankText Error text to display if the allow blank validation fails (defaults to "This field is required") */ @@ -124,13 +128,14 @@ Roo.extend(Roo.form.TextField, Roo.form.Field, { else if(this.validationEvent !== false){ this.el.on(this.validationEvent, this.validate, this, {buffer: this.validationDelay}); } - if(this.selectOnFocus || this.emptyText){ + + if(this.selectOnFocus){ this.on("focus", this.preFocus, this); - if(this.emptyText){ - this.on('blur', this.postBlur, this); - - } } + if (!this.allowLeadingSpace) { + this.on('blur', this.cleanLeadingSpace, this); + } + if(this.maskRe || (this.vtype && this.disableKeyFilter !== true && (this.maskRe = Roo.form.VTypes[this.vtype+'Mask']))){ this.el.on("keypress", this.filterKeys, this); } @@ -166,7 +171,11 @@ Roo.extend(Roo.form.TextField, Roo.form.Field, { this.autoSize(); } }, - + // private - clean the leading white space + cleanLeadingSpace : function(e) + { + this.setValue(this.getValue().replace(/^\s+/,'')); + }, /** * Resets the current field value to the originally-loaded value and clears any validation messages. * @@ -174,9 +183,7 @@ Roo.extend(Roo.form.TextField, Roo.form.Field, { reset : function(){ Roo.form.TextField.superclass.reset.call(this); - }, - - + }, // private preFocus : function(){ @@ -185,11 +192,7 @@ Roo.extend(Roo.form.TextField, Roo.form.Field, { } }, - // private - postBlur : function(){ - - }, - + // private filterKeys : function(e){ var k = e.getKey(); @@ -318,12 +321,14 @@ Roo.extend(Roo.form.TextField, Roo.form.Field, { return; } - if(isSelectAll){ // backspace and delete key + if(isSelectAll && event.getCharCode() > 31){ // backspace and delete key event.preventDefault(); // this is very hacky as keydown always get's upper case. - // + var cc = String.fromCharCode(event.getCharCode()); + + this.setValue( event.shiftKey ? cc : cc.toLowerCase()); }