From 6e59a4f5778967dd8ec139dcbefb193e1e6eb3d1 Mon Sep 17 00:00:00 2001 From: Alan Date: Wed, 20 Mar 2024 15:28:11 +0800 Subject: [PATCH] readonly for date fields should not show popup --- Roo/bootstrap/form/DateField.js | 6 ++--- Roo/form/DateField.js | 2 +- docs/src/Roo_bootstrap_form_DateField.js.html | 5 +++- roojs-all.js | 2 +- roojs-bootstrap-debug.js | 5 +++- roojs-bootstrap.js | 25 ++++++++++--------- roojs-debug.js | 2 +- roojs-ui-debug.js | 2 +- roojs-ui.js | 2 +- 9 files changed, 29 insertions(+), 22 deletions(-) diff --git a/Roo/bootstrap/form/DateField.js b/Roo/bootstrap/form/DateField.js index a4899754c3..0304545619 100644 --- a/Roo/bootstrap/form/DateField.js +++ b/Roo/bootstrap/form/DateField.js @@ -564,9 +564,9 @@ Roo.extend(Roo.bootstrap.form.DateField, Roo.bootstrap.form.Input, { showPopup : function() { if(this.readOnly) { - return; - } - this.picker().show(); + return; + } + this.picker().show(); this.update(); this.place(); diff --git a/Roo/form/DateField.js b/Roo/form/DateField.js index 030f671226..cf7a5571a1 100644 --- a/Roo/form/DateField.js +++ b/Roo/form/DateField.js @@ -341,7 +341,7 @@ dateField.setValue('2006-5-4'); // private // Implements the default empty TriggerField.onTriggerClick function to display the DatePicker onTriggerClick : function(){ - if(this.disabled){ + if(this.disabled || this.readOnly){ return; } if(this.menu == null){ diff --git a/docs/src/Roo_bootstrap_form_DateField.js.html b/docs/src/Roo_bootstrap_form_DateField.js.html index aad13efa53..612c10361f 100644 --- a/docs/src/Roo_bootstrap_form_DateField.js.html +++ b/docs/src/Roo_bootstrap_form_DateField.js.html @@ -563,7 +563,10 @@ showPopup : function() { - this.picker().show(); + if(this.readOnly) { + return; + } + this.picker().show(); this.update(); this.place(); diff --git a/roojs-all.js b/roojs-all.js index 80796a5043..83244c885e 100644 --- a/roojs-all.js +++ b/roojs-all.js @@ -1840,7 +1840,7 @@ return false;}}}var E=this.formatDate(A);if(this.ddMatch&&this.ddMatch.test(E)){ }Roo.form.DateField.superclass.setValue.call(this,this.formatDate(this.parseDate(A)));this.value=this.parseDate(A);},parseDate:function(A){if(A instanceof Date){if(A.datepicker-years tbody td',t return;}this.picker().addClass('bottom');this.picker().setTop(this.inputEl().getBottom()).setLeft(this.inputEl().getLeft());},parseDate:function(A){if(!A){return false;}if(A instanceof Date){return A;}var v=Date.parseDate(A,'Y-m-d');return (typeof(v)=='undefined')?false:v; },formatDate:function(A,B){return (!A||!(A instanceof Date))?A:A.dateFormat(B||this.format);},translateDate:function(A){switch(this.language){case 'zh_CN':return new Intl.DateTimeFormat('zh-CN',{year:'numeric',month:'long',day:'numeric'}).format(A);default:return this.formatDate(A); }},onFocus:function(){Roo.bootstrap.form.DateField.superclass.onFocus.call(this);this.showPopup();},onBlur:function(){Roo.bootstrap.form.DateField.superclass.onBlur.call(this);if(!this.readOnly){var d=this.inputEl().getValue();var A=this.parseDate(d);if(A){this.setValue(A); -}else{this.setValue(this.getValue());}}this.hidePopup();},showPopup:function(){this.picker().show();this.update();this.place();this.fireEvent('showpopup',this,this.date);},hidePopup:function(){if(this.isInline){return;}this.picker().hide();this.viewMode=this.startViewMode; -this.showMode();this.inputEl().blur();this.fireEvent('hidepopup',this,this.date);},onMousedown:function(e){e.stopPropagation();e.preventDefault();},keyup:function(e){Roo.bootstrap.form.DateField.superclass.keyup.call(this);this.update();},setValue:function(v){if(this.fireEvent('beforeselect',this,v)!==false){var d=this.parseDate(v); -if(!d){this.date=this.viewDate=this.value=this.hiddenField.value='';if(this.rendered){this.inputEl().dom.value='';this.validate();}return;}d=new Date(d).clearTime();this.value=this.hiddenField.value=d.dateFormat('Y-m-d');v=this.translateDate(d);if(this.rendered){this.inputEl().dom.value=(v===null||v===undefined?'':v); -this.validate();}this.date=new Date(d.getTime()-d.getTimezoneOffset()*60000);this.update();this.fireEvent('select',this,this.date);}},setRawValue:function(v){if(this.fireEvent('beforeselect',this,v)!==false){var d=this.parseDate(v);if(!d){this.date=this.viewDate=this.value=this.hiddenField.value=''; -if(this.rendered){this.inputEl().dom.value=(v===null||v===undefined?'':v);}return;}d=new Date(d).clearTime();this.value=this.hiddenField.value=d.dateFormat('Y-m-d');v=this.translateDate(d);if(this.rendered){this.inputEl().dom.value=(v===null||v===undefined?'':v); -}this.date=new Date(d.getTime()-d.getTimezoneOffset()*60000);this.update();this.fireEvent('select',this,this.date);}},getValue:function(){return this.value;},getRawValue:function(){return this.getValue();},fireKey:function(e){if(!this.picker().isVisible()){if(e.keyCode==27){this.showPopup(); -}return;}var A=false,B,C,D,E,F;switch(e.keyCode){case 27:this.hidePopup();e.preventDefault();break;case 37:case 39:if(!this.keyboardNavigation){break;}B=e.keyCode==37?-1:1;if(e.ctrlKey){E=this.moveYear(this.date,B);F=this.moveYear(this.viewDate,B);}else if(e.shiftKey){E=this.moveMonth(this.date,B); -F=this.moveMonth(this.viewDate,B);}else{E=new Date(this.date);E.setUTCDate(this.date.getUTCDate()+B);F=new Date(this.viewDate);F.setUTCDate(this.viewDate.getUTCDate()+B);}if(this.dateWithinRange(E)){this.date=E;this.viewDate=F;this.setValue(this.date);e.preventDefault(); -A=true;}break;case 38:case 40:if(!this.keyboardNavigation){break;}B=e.keyCode==38?-1:1;if(e.ctrlKey){E=this.moveYear(this.date,B);F=this.moveYear(this.viewDate,B);}else if(e.shiftKey){E=this.moveMonth(this.date,B);F=this.moveMonth(this.viewDate,B);}else{E=new Date(this.date); -E.setUTCDate(this.date.getUTCDate()+B*7);F=new Date(this.viewDate);F.setUTCDate(this.viewDate.getUTCDate()+B*7);}if(this.dateWithinRange(E)){this.date=E;this.viewDate=F;this.setValue(this.date);e.preventDefault();A=true;}break;case 13:this.setValue(this.date); -this.hidePopup();e.preventDefault();break;case 9:this.setValue(this.date);this.hidePopup();break;case 16:case 17:case 18:break;default:this.hidePopup();}},onClick:function(e){e.stopPropagation();e.preventDefault();var A=e.getTarget();if(A.nodeName.toLowerCase()==='i'){A=Roo.get(A).dom.parentNode; -}var B=A.nodeName;var C=A.className;var D=A.innerHTML;switch(B.toLowerCase()){case 'th':switch(C){case 'switch':this.showMode(1);break;case 'prev':case 'next':var E=Roo.bootstrap.form.DateField.modes[this.viewMode].navStep*(C=='prev'?-1:1);switch(this.viewMode){case 0:this.viewDate=this.moveMonth(this.viewDate,E); +}else{this.setValue(this.getValue());}}this.hidePopup();},showPopup:function(){if(this.readOnly){return;}this.picker().show();this.update();this.place();this.fireEvent('showpopup',this,this.date);},hidePopup:function(){if(this.isInline){return;}this.picker().hide(); +this.viewMode=this.startViewMode;this.showMode();this.inputEl().blur();this.fireEvent('hidepopup',this,this.date);},onMousedown:function(e){e.stopPropagation();e.preventDefault();},keyup:function(e){Roo.bootstrap.form.DateField.superclass.keyup.call(this); +this.update();},setValue:function(v){if(this.fireEvent('beforeselect',this,v)!==false){var d=this.parseDate(v);if(!d){this.date=this.viewDate=this.value=this.hiddenField.value='';if(this.rendered){this.inputEl().dom.value='';this.validate();}return;}d=new Date(d).clearTime(); +this.value=this.hiddenField.value=d.dateFormat('Y-m-d');v=this.translateDate(d);if(this.rendered){this.inputEl().dom.value=(v===null||v===undefined?'':v);this.validate();}this.date=new Date(d.getTime()-d.getTimezoneOffset()*60000);this.update();this.fireEvent('select',this,this.date); +}},setRawValue:function(v){if(this.fireEvent('beforeselect',this,v)!==false){var d=this.parseDate(v);if(!d){this.date=this.viewDate=this.value=this.hiddenField.value='';if(this.rendered){this.inputEl().dom.value=(v===null||v===undefined?'':v);}return;}d=new Date(d).clearTime(); +this.value=this.hiddenField.value=d.dateFormat('Y-m-d');v=this.translateDate(d);if(this.rendered){this.inputEl().dom.value=(v===null||v===undefined?'':v);}this.date=new Date(d.getTime()-d.getTimezoneOffset()*60000);this.update();this.fireEvent('select',this,this.date); +}},getValue:function(){return this.value;},getRawValue:function(){return this.getValue();},fireKey:function(e){if(!this.picker().isVisible()){if(e.keyCode==27){this.showPopup();}return;}var A=false,B,C,D,E,F;switch(e.keyCode){case 27:this.hidePopup();e.preventDefault(); +break;case 37:case 39:if(!this.keyboardNavigation){break;}B=e.keyCode==37?-1:1;if(e.ctrlKey){E=this.moveYear(this.date,B);F=this.moveYear(this.viewDate,B);}else if(e.shiftKey){E=this.moveMonth(this.date,B);F=this.moveMonth(this.viewDate,B);}else{E=new Date(this.date); +E.setUTCDate(this.date.getUTCDate()+B);F=new Date(this.viewDate);F.setUTCDate(this.viewDate.getUTCDate()+B);}if(this.dateWithinRange(E)){this.date=E;this.viewDate=F;this.setValue(this.date);e.preventDefault();A=true;}break;case 38:case 40:if(!this.keyboardNavigation){break; +}B=e.keyCode==38?-1:1;if(e.ctrlKey){E=this.moveYear(this.date,B);F=this.moveYear(this.viewDate,B);}else if(e.shiftKey){E=this.moveMonth(this.date,B);F=this.moveMonth(this.viewDate,B);}else{E=new Date(this.date);E.setUTCDate(this.date.getUTCDate()+B*7);F=new Date(this.viewDate); +F.setUTCDate(this.viewDate.getUTCDate()+B*7);}if(this.dateWithinRange(E)){this.date=E;this.viewDate=F;this.setValue(this.date);e.preventDefault();A=true;}break;case 13:this.setValue(this.date);this.hidePopup();e.preventDefault();break;case 9:this.setValue(this.date); +this.hidePopup();break;case 16:case 17:case 18:break;default:this.hidePopup();}},onClick:function(e){e.stopPropagation();e.preventDefault();var A=e.getTarget();if(A.nodeName.toLowerCase()==='i'){A=Roo.get(A).dom.parentNode;}var B=A.nodeName;var C=A.className; +var D=A.innerHTML;switch(B.toLowerCase()){case 'th':switch(C){case 'switch':this.showMode(1);break;case 'prev':case 'next':var E=Roo.bootstrap.form.DateField.modes[this.viewMode].navStep*(C=='prev'?-1:1);switch(this.viewMode){case 0:this.viewDate=this.moveMonth(this.viewDate,E); break;case 1:case 2:this.viewDate=this.moveYear(this.viewDate,E);break;}this.fill();break;case 'today':var F=new Date();this.date=this.UTCDate(F.getFullYear(),F.getMonth(),F.getDate(),0,0,0);this.setValue(this.date);this.hidePopup();break;}break;case 'span':if(C.indexOf('disabled')<0){if(!this.viewDate){this.viewDate=new Date(); }this.viewDate.setUTCDate(1);if(C.indexOf('month')>-1){this.viewDate.setUTCMonth(Roo.bootstrap.form.DateField.dates[this.language].monthsShort.indexOf(D));}else{var G=parseInt(D,10)||0;this.viewDate.setUTCFullYear(G);}if(this.singleMode){this.setValue(this.viewDate); this.hidePopup();return;}this.showMode(-1);this.fill();}break;case 'td':if(C.indexOf('day')>-1&&C.indexOf('disabled')<0){var H=parseInt(D,10)||1;var G=(this.viewDate||new Date()).getUTCFullYear(),I=(this.viewDate||new Date()).getUTCMonth();if(C.indexOf('old')>-1){if(I===0){I=11; diff --git a/roojs-debug.js b/roojs-debug.js index 3fc22337d7..a82eef944f 100644 --- a/roojs-debug.js +++ b/roojs-debug.js @@ -44327,7 +44327,7 @@ dateField.setValue('2006-5-4'); // private // Implements the default empty TriggerField.onTriggerClick function to display the DatePicker onTriggerClick : function(){ - if(this.disabled){ + if(this.disabled || this.readOnly){ return; } if(this.menu == null){ diff --git a/roojs-ui-debug.js b/roojs-ui-debug.js index 8438c714bc..2b5a472c39 100644 --- a/roojs-ui-debug.js +++ b/roojs-ui-debug.js @@ -19825,7 +19825,7 @@ dateField.setValue('2006-5-4'); // private // Implements the default empty TriggerField.onTriggerClick function to display the DatePicker onTriggerClick : function(){ - if(this.disabled){ + if(this.disabled || this.readOnly){ return; } if(this.menu == null){ diff --git a/roojs-ui.js b/roojs-ui.js index 45b5682a21..0675b4922f 100644 --- a/roojs-ui.js +++ b/roojs-ui.js @@ -893,7 +893,7 @@ return false;}}}var E=this.formatDate(A);if(this.ddMatch&&this.ddMatch.test(E)){ }Roo.form.DateField.superclass.setValue.call(this,this.formatDate(this.parseDate(A)));this.value=this.parseDate(A);},parseDate:function(A){if(A instanceof Date){if(A