projects
/
roojs1
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Fix #5944 - trim leading white space from input textfields
[roojs1]
/
Roo
/
form
/
TextField.js
diff --git
a/Roo/form/TextField.js
b/Roo/form/TextField.js
index
f68c13a
..
20a8c7d
100644
(file)
--- 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} 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")
*/
/**
* @cfg {String} blankText Error text to display if the allow blank validation fails (defaults to "This field is required")
*/
@@
-104,17
+108,18
@@
Roo.extend(Roo.form.TextField, Roo.form.Field, {
*/
regexText : "",
/**
*/
regexText : "",
/**
- * @cfg {String} emptyText The default text to display in an empty field (defaults to null).
+ * @cfg {String} emptyText The default text to display in an empty field
- placeholder...
(defaults to null).
*/
emptyText : null,
*/
emptyText : null,
- /**
- * @cfg {String} emptyClass The CSS class to apply to an empty field to style the {@link #emptyText} (defaults to
- * 'x-form-empty-field'). This class is automatically added and removed as needed depending on the current field value.
- */
- emptyClass : 'x-form-empty-field',
+
// private
// private
- initEvents : function(){
+ initEvents : function()
+ {
+ if (this.emptyText) {
+ this.el.attr('placeholder', this.emptyText);
+ }
+
Roo.form.TextField.superclass.initEvents.call(this);
if(this.validationEvent == 'keyup'){
this.validationTask = new Roo.util.DelayedTask(this.validate, this);
Roo.form.TextField.superclass.initEvents.call(this);
if(this.validationEvent == 'keyup'){
this.validationTask = new Roo.util.DelayedTask(this.validate, this);
@@
-123,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});
}
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);
this.on("focus", this.preFocus, this);
- if(this.emptyText){
- this.on('blur', this.postBlur, this);
- this.applyEmptyText();
- }
}
}
+ 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);
}
if(this.maskRe || (this.vtype && this.disableKeyFilter !== true && (this.maskRe = Roo.form.VTypes[this.vtype+'Mask']))){
this.el.on("keypress", this.filterKeys, this);
}
@@
-165,41
+171,28
@@
Roo.extend(Roo.form.TextField, Roo.form.Field, {
this.autoSize();
}
},
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.
/**
* Resets the current field value to the originally-loaded value and clears any validation messages.
- *
Also adds emptyText and emptyClass if the original value was blank.
+ *
*/
reset : function(){
Roo.form.TextField.superclass.reset.call(this);
*/
reset : function(){
Roo.form.TextField.superclass.reset.call(this);
- this.applyEmptyText();
- },
-
- applyEmptyText : function(){
- if(this.rendered && this.emptyText && this.getRawValue().length < 1){
- this.setRawValue(this.emptyText);
- this.el.addClass(this.emptyClass);
- }
- },
-
+
+ },
// private
preFocus : function(){
// private
preFocus : function(){
- if(this.emptyText){
- if(this.el.dom.value == this.emptyText){
- this.setRawValue('');
- }
- this.el.removeClass(this.emptyClass);
- }
+
if(this.selectOnFocus){
this.el.dom.select();
}
},
if(this.selectOnFocus){
this.el.dom.select();
}
},
- // private
- postBlur : function(){
- this.applyEmptyText();
- },
-
+
// private
filterKeys : function(e){
var k = e.getKey();
// private
filterKeys : function(e){
var k = e.getKey();
@@
-216,11
+209,9
@@
Roo.extend(Roo.form.TextField, Roo.form.Field, {
},
setValue : function(v){
},
setValue : function(v){
- if(this.emptyText && this.el && v !== undefined && v !== null && v !== ''){
- this.el.removeClass(this.emptyClass);
- }
+
Roo.form.TextField.superclass.setValue.apply(this, arguments);
Roo.form.TextField.superclass.setValue.apply(this, arguments);
- this.applyEmptyText();
+
this.autoSize();
},
this.autoSize();
},
@@
-231,7
+222,7
@@
Roo.extend(Roo.form.TextField, Roo.form.Field, {
* @return {Boolean} True if the value is valid, else false
*/
validateValue : function(value){
* @return {Boolean} True if the value is valid, else false
*/
validateValue : function(value){
- if(value.length < 1
|| value === this.emptyText)
{ // if it's blank
+ if(value.length < 1
)
{ // if it's blank
if(this.allowBlank){
this.clearInvalid();
return true;
if(this.allowBlank){
this.clearInvalid();
return true;
@@
-330,12
+321,14
@@
Roo.extend(Roo.form.TextField, Roo.form.Field, {
return;
}
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.
event.preventDefault();
// this is very hacky as keydown always get's upper case.
- //
+
var cc = String.fromCharCode(event.getCharCode());
var cc = String.fromCharCode(event.getCharCode());
+
+
this.setValue( event.shiftKey ? cc : cc.toLowerCase());
}
this.setValue( event.shiftKey ? cc : cc.toLowerCase());
}