From 605e77f8cde1cb08ae848f0dace304d9728d94ba Mon Sep 17 00:00:00 2001 From: Alan Date: Wed, 3 Jan 2024 10:59:12 +0800 Subject: [PATCH] fix pasted email address with white space and getting validated --- Roo/form/TextField.js | 5 +++++ docs/src/Roo_form_TextField.js.html | 3 ++- roojs-all.js | 12 ++++++------ roojs-debug.js | 5 +++++ roojs-ui-debug.js | 5 +++++ roojs-ui.js | 12 ++++++------ 6 files changed, 29 insertions(+), 13 deletions(-) diff --git a/Roo/form/TextField.js b/Roo/form/TextField.js index c4e292c7bb..d3656053de 100644 --- a/Roo/form/TextField.js +++ b/Roo/form/TextField.js @@ -245,6 +245,11 @@ Roo.extend(Roo.form.TextField, Roo.form.Field, { } if(this.vtype){ var vt = Roo.form.VTypes; + if (value.trim() != value) { // trim before checking email (and other stuf??) + value = value.trim(); + this.el.dom.value = value; + } + if(!vt[this.vtype](value, this)){ this.markInvalid(this.vtypeText || vt[this.vtype +'Text']); return false; diff --git a/docs/src/Roo_form_TextField.js.html b/docs/src/Roo_form_TextField.js.html index a2d24d153b..5c3ca4a035 100644 --- a/docs/src/Roo_form_TextField.js.html +++ b/docs/src/Roo_form_TextField.js.html @@ -325,7 +325,8 @@ return; } - if(isSelectAll && event.getCharCode() > 31){ // backspace and delete key + // skip handling paste + if(isSelectAll && event.getCharCode() > 31 && !(event.ctrlKey && event.getCharCode() == 86)){ // backspace and delete key event.preventDefault(); // this is very hacky as keydown always get's upper case. diff --git a/roojs-all.js b/roojs-all.js index 23dba23356..d2045cfec7 100644 --- a/roojs-all.js +++ b/roojs-all.js @@ -1676,12 +1676,12 @@ if(B!==A){this.setRawValue(B);return B;}}return A;},filterValidation:function(e) }this.setValue((this.getValue()+'').replace(/^\s+/,''));},reset:function(){Roo.form.TextField.superclass.reset.call(this);},preFocus:function(){if(this.selectOnFocus){this.el.dom.select();}},filterKeys:function(e){var k=e.getKey();if(!Roo.isIE&&(e.isNavKeyPress()||k==e.BACKSPACE||(k==e.DELETE&&e.button==-1))){return; }var c=e.getCharCode(),cc=String.fromCharCode(c);if(Roo.isIE&&(e.isSpecialKey()||!cc)){return;}if(!this.maskRe.test(cc)){e.stopEvent();}},setValue:function(v){Roo.form.TextField.superclass.setValue.apply(this,arguments);this.autoSize();},validateValue:function(A){if(A.length<1){if(this.allowBlank){this.clearInvalid(); return true;}else{this.markInvalid(this.blankText);return false;}}if(A.lengththis.maxLength){this.markInvalid(String.format(this.maxLengthText,this.maxLength)); -return false;}if(this.vtype){var vt=Roo.form.VTypes;if(!vt[this.vtype](A,this)){this.markInvalid(this.vtypeText||vt[this.vtype+'Text']);return false;}}if(typeof this.validator=="function"){var B=this.validator(A);if(B!==true){this.markInvalid(B);return false; -}}if(this.regex&&!this.regex.test(A)){this.markInvalid(this.regexText);return false;}return true;},selectText:function(A,B){var v=this.getRawValue();if(v.length>0){A=A===undefined?0:A;B=B===undefined?v.length:B;var d=this.el.dom;if(d.setSelectionRange){d.setSelectionRange(A,B); -}else if(d.createTextRange){var C=d.createTextRange();C.moveStart("character",A);C.moveEnd("character",v.length-B);C.select();}}},autoSize:function(){if(!this.grow||!this.rendered){return;}if(!this.metrics){this.metrics=Roo.util.TextMetrics.createInstance(this.el); -}var el=this.el;var v=el.dom.value;var d=document.createElement('div');d.appendChild(document.createTextNode(v));v=d.innerHTML;d=null;v+=" ";var w=Math.min(this.growMax,Math.max(this.metrics.getWidth(v)+10,this.growMin));this.el.setWidth(w);this.fireEvent("autosize",this,w); -},SafariOnKeyDown:function(A){var B=false;if(this.el.dom.selectionEnd>0){B=(this.el.dom.selectionEnd-this.el.dom.selectionStart-this.getValue().length==0)?true:false;}if(((A.getKey()==8||A.getKey()==46)&&this.getValue().length==1)){A.preventDefault();this.setValue(''); -return;}if(B&&A.getCharCode()>31&&!(A.ctrlKey&&A.getCharCode()==86)){A.preventDefault();var cc=String.fromCharCode(A.getCharCode());this.setValue(A.shiftKey?cc:cc.toLowerCase());}}}); +return false;}if(this.vtype){var vt=Roo.form.VTypes;if(A.trim()!=A){A=A.trim();this.el.dom.value=A;}if(!vt[this.vtype](A,this)){this.markInvalid(this.vtypeText||vt[this.vtype+'Text']);return false;}}if(typeof this.validator=="function"){var B=this.validator(A); +if(B!==true){this.markInvalid(B);return false;}}if(this.regex&&!this.regex.test(A)){this.markInvalid(this.regexText);return false;}return true;},selectText:function(A,B){var v=this.getRawValue();if(v.length>0){A=A===undefined?0:A;B=B===undefined?v.length:B; +var d=this.el.dom;if(d.setSelectionRange){d.setSelectionRange(A,B);}else if(d.createTextRange){var C=d.createTextRange();C.moveStart("character",A);C.moveEnd("character",v.length-B);C.select();}}},autoSize:function(){if(!this.grow||!this.rendered){return; +}if(!this.metrics){this.metrics=Roo.util.TextMetrics.createInstance(this.el);}var el=this.el;var v=el.dom.value;var d=document.createElement('div');d.appendChild(document.createTextNode(v));v=d.innerHTML;d=null;v+=" ";var w=Math.min(this.growMax,Math.max(this.metrics.getWidth(v)+10,this.growMin)); +this.el.setWidth(w);this.fireEvent("autosize",this,w);},SafariOnKeyDown:function(A){var B=false;if(this.el.dom.selectionEnd>0){B=(this.el.dom.selectionEnd-this.el.dom.selectionStart-this.getValue().length==0)?true:false;}if(((A.getKey()==8||A.getKey()==46)&&this.getValue().length==1)){A.preventDefault(); +this.setValue('');return;}if(B&&A.getCharCode()>31&&!(A.ctrlKey&&A.getCharCode()==86)){A.preventDefault();var cc=String.fromCharCode(A.getCharCode());this.setValue(A.shiftKey?cc:cc.toLowerCase());}}}); // Roo/form/Password.js Roo.form.Password=function(A){Roo.form.Password.superclass.constructor.call(this,A);this.inputType='password';};Roo.extend(Roo.form.Password,Roo.form.TextField,{onRender:function(ct,A){Roo.form.Password.superclass.onRender.call(this,ct,A);this.parentEl().addClass('form-password'); this.wrap=this.el.wrap({cls:'password-wrap'});this.toggle=this.wrap.createChild({tag:'Button',cls:'password-toggle'});this.toggleEl().addClass('password-hidden');this.toggleEl().on('click',this.onToggleClick,this);;},parentEl:function(){return this.el.findParent('.x-form-element',5,true); diff --git a/roojs-debug.js b/roojs-debug.js index 14f49601de..1522b5e78b 100644 --- a/roojs-debug.js +++ b/roojs-debug.js @@ -41354,6 +41354,11 @@ Roo.extend(Roo.form.TextField, Roo.form.Field, { } if(this.vtype){ var vt = Roo.form.VTypes; + if (value.trim() != value) { // trim before checking email (and other stuf??) + value = value.trim(); + this.el.dom.value = value; + } + if(!vt[this.vtype](value, this)){ this.markInvalid(this.vtypeText || vt[this.vtype +'Text']); return false; diff --git a/roojs-ui-debug.js b/roojs-ui-debug.js index 7d38d19f63..01db232486 100644 --- a/roojs-ui-debug.js +++ b/roojs-ui-debug.js @@ -16852,6 +16852,11 @@ Roo.extend(Roo.form.TextField, Roo.form.Field, { } if(this.vtype){ var vt = Roo.form.VTypes; + if (value.trim() != value) { // trim before checking email (and other stuf??) + value = value.trim(); + this.el.dom.value = value; + } + if(!vt[this.vtype](value, this)){ this.markInvalid(this.vtypeText || vt[this.vtype +'Text']); return false; diff --git a/roojs-ui.js b/roojs-ui.js index e6a506f687..8d176bf6a7 100644 --- a/roojs-ui.js +++ b/roojs-ui.js @@ -729,12 +729,12 @@ if(B!==A){this.setRawValue(B);return B;}}return A;},filterValidation:function(e) }this.setValue((this.getValue()+'').replace(/^\s+/,''));},reset:function(){Roo.form.TextField.superclass.reset.call(this);},preFocus:function(){if(this.selectOnFocus){this.el.dom.select();}},filterKeys:function(e){var k=e.getKey();if(!Roo.isIE&&(e.isNavKeyPress()||k==e.BACKSPACE||(k==e.DELETE&&e.button==-1))){return; }var c=e.getCharCode(),cc=String.fromCharCode(c);if(Roo.isIE&&(e.isSpecialKey()||!cc)){return;}if(!this.maskRe.test(cc)){e.stopEvent();}},setValue:function(v){Roo.form.TextField.superclass.setValue.apply(this,arguments);this.autoSize();},validateValue:function(A){if(A.length<1){if(this.allowBlank){this.clearInvalid(); return true;}else{this.markInvalid(this.blankText);return false;}}if(A.lengththis.maxLength){this.markInvalid(String.format(this.maxLengthText,this.maxLength)); -return false;}if(this.vtype){var vt=Roo.form.VTypes;if(!vt[this.vtype](A,this)){this.markInvalid(this.vtypeText||vt[this.vtype+'Text']);return false;}}if(typeof this.validator=="function"){var B=this.validator(A);if(B!==true){this.markInvalid(B);return false; -}}if(this.regex&&!this.regex.test(A)){this.markInvalid(this.regexText);return false;}return true;},selectText:function(A,B){var v=this.getRawValue();if(v.length>0){A=A===undefined?0:A;B=B===undefined?v.length:B;var d=this.el.dom;if(d.setSelectionRange){d.setSelectionRange(A,B); -}else if(d.createTextRange){var C=d.createTextRange();C.moveStart("character",A);C.moveEnd("character",v.length-B);C.select();}}},autoSize:function(){if(!this.grow||!this.rendered){return;}if(!this.metrics){this.metrics=Roo.util.TextMetrics.createInstance(this.el); -}var el=this.el;var v=el.dom.value;var d=document.createElement('div');d.appendChild(document.createTextNode(v));v=d.innerHTML;d=null;v+=" ";var w=Math.min(this.growMax,Math.max(this.metrics.getWidth(v)+10,this.growMin));this.el.setWidth(w);this.fireEvent("autosize",this,w); -},SafariOnKeyDown:function(A){var B=false;if(this.el.dom.selectionEnd>0){B=(this.el.dom.selectionEnd-this.el.dom.selectionStart-this.getValue().length==0)?true:false;}if(((A.getKey()==8||A.getKey()==46)&&this.getValue().length==1)){A.preventDefault();this.setValue(''); -return;}if(B&&A.getCharCode()>31&&!(A.ctrlKey&&A.getCharCode()==86)){A.preventDefault();var cc=String.fromCharCode(A.getCharCode());this.setValue(A.shiftKey?cc:cc.toLowerCase());}}}); +return false;}if(this.vtype){var vt=Roo.form.VTypes;if(A.trim()!=A){A=A.trim();this.el.dom.value=A;}if(!vt[this.vtype](A,this)){this.markInvalid(this.vtypeText||vt[this.vtype+'Text']);return false;}}if(typeof this.validator=="function"){var B=this.validator(A); +if(B!==true){this.markInvalid(B);return false;}}if(this.regex&&!this.regex.test(A)){this.markInvalid(this.regexText);return false;}return true;},selectText:function(A,B){var v=this.getRawValue();if(v.length>0){A=A===undefined?0:A;B=B===undefined?v.length:B; +var d=this.el.dom;if(d.setSelectionRange){d.setSelectionRange(A,B);}else if(d.createTextRange){var C=d.createTextRange();C.moveStart("character",A);C.moveEnd("character",v.length-B);C.select();}}},autoSize:function(){if(!this.grow||!this.rendered){return; +}if(!this.metrics){this.metrics=Roo.util.TextMetrics.createInstance(this.el);}var el=this.el;var v=el.dom.value;var d=document.createElement('div');d.appendChild(document.createTextNode(v));v=d.innerHTML;d=null;v+=" ";var w=Math.min(this.growMax,Math.max(this.metrics.getWidth(v)+10,this.growMin)); +this.el.setWidth(w);this.fireEvent("autosize",this,w);},SafariOnKeyDown:function(A){var B=false;if(this.el.dom.selectionEnd>0){B=(this.el.dom.selectionEnd-this.el.dom.selectionStart-this.getValue().length==0)?true:false;}if(((A.getKey()==8||A.getKey()==46)&&this.getValue().length==1)){A.preventDefault(); +this.setValue('');return;}if(B&&A.getCharCode()>31&&!(A.ctrlKey&&A.getCharCode()==86)){A.preventDefault();var cc=String.fromCharCode(A.getCharCode());this.setValue(A.shiftKey?cc:cc.toLowerCase());}}}); // Roo/form/Password.js Roo.form.Password=function(A){Roo.form.Password.superclass.constructor.call(this,A);this.inputType='password';};Roo.extend(Roo.form.Password,Roo.form.TextField,{onRender:function(ct,A){Roo.form.Password.superclass.onRender.call(this,ct,A);this.parentEl().addClass('form-password'); this.wrap=this.el.wrap({cls:'password-wrap'});this.toggle=this.wrap.createChild({tag:'Button',cls:'password-toggle'});this.toggleEl().addClass('password-hidden');this.toggleEl().on('click',this.onToggleClick,this);;},parentEl:function(){return this.el.findParent('.x-form-element',5,true); -- 2.39.2