Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix date TV parsing bug when time is hidden #16398

Merged
merged 2 commits into from May 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 8 additions & 1 deletion core/src/Revolution/Processors/Resource/Create.php
Expand Up @@ -507,7 +507,14 @@ public function addTemplateVariables()
$value = implode(',', $newTags);
break;
case 'date':
$value = empty($value) ? '' : date('Y-m-d H:i:s', strtotime($value));
$tvProperties = $tv->get('input_properties');
if (!empty($value)) {
$dateTime = new \DateTime($value);
if (array_key_exists('hideTime', $tvProperties) && (bool)$tvProperties['hideTime']) {
$dateTime->setTime(0, 0, 0, 0);
}
$value = $dateTime->format('Y-m-d H:i:s');
}
break;
case 'url':
if ($this->getProperty($tvKey . '_prefix', '--') != '--') {
Expand Down
9 changes: 8 additions & 1 deletion core/src/Revolution/Processors/Resource/Update.php
Expand Up @@ -745,7 +745,14 @@ public function saveTemplateVariables()
}
break;
case 'date':
$value = empty($value) ? '' : date('Y-m-d H:i:s', strtotime($value));
$tvProperties = $tv->get('input_properties');
if (!empty($value)) {
$dateTime = new \DateTime($value);
if (array_key_exists('hideTime', $tvProperties) && (bool)$tvProperties['hideTime']) {
$dateTime->setTime(0, 0, 0, 0);
}
$value = $dateTime->format('Y-m-d H:i:s');
}
break;
/* ensure tag types trim whitespace from tags */
case 'tag':
Expand Down
2 changes: 1 addition & 1 deletion manager/assets/modext/modx.jsgrps-min.js

Large diffs are not rendered by default.

78 changes: 34 additions & 44 deletions manager/assets/modext/util/datetime.js
Expand Up @@ -15,7 +15,7 @@ Ext.ux.form.DateTime = Ext.extend(Ext.form.Field, {
* @cfg {Function} dateValidator A custom validation function to be called during date field
* validation (defaults to null)
*/
dateValidator:null
dateValidator:null
/**
* @cfg {String/Object} defaultAutoCreate DomHelper element spec
* Let superclass to create hidden field instead of textbox. Hidden will be submittend to server
Expand All @@ -30,11 +30,6 @@ Ext.ux.form.DateTime = Ext.extend(Ext.form.Field, {
* and submitted to server (defaults to 'Y-m-d H:i:s' that is mysql format)
*/
,hiddenFormat:'Y-m-d H:i:s'
/**
* @cfg {String} hiddenFormatForTimeHidden Format of datetime used to store value in hidden field
* and submitted to server when `hideTime` is set to `true` (defaults to 'Y-m-d 00:00:00' that is mysql format)
*/
,hiddenFormatForTimeHidden:'Y-m-d 00:00:00'
/**
* @cfg {Boolean} otherToNow Set other field to now() if not explicly filled in (defaults to true)
*/
Expand Down Expand Up @@ -93,13 +88,9 @@ Ext.ux.form.DateTime = Ext.extend(Ext.form.Field, {
this.offset_time = 0;
}

if (this.hideTime) {
this.hiddenFormat = this.hiddenFormatForTimeHidden;
}

// create DateField
var dateConfig = Ext.apply({}, {
id:this.id + '-date'
id:this.id + '-date'
,format:this.dateFormat || Ext.form.DateField.prototype.format
,width:this.timeWidth
,selectOnFocus:this.selectOnFocus
Expand All @@ -113,8 +104,8 @@ Ext.ux.form.DateTime = Ext.extend(Ext.form.Field, {
,allowBlank: this.allowBlank
,msgTarget: this.msgTarget
,listeners:{
blur:{scope:this, fn:this.onBlur}
,focus:{scope:this, fn:this.onFocus}
blur:{scope:this, fn:this.onBlur}
,focus:{scope:this, fn:this.onFocus}
}
}, this.dateConfig);
this.df = new Ext.form.DateField(dateConfig);
Expand All @@ -128,7 +119,7 @@ Ext.ux.form.DateTime = Ext.extend(Ext.form.Field, {

// create TimeField
var timeConfig = Ext.apply({}, {
id:this.id + '-time'
id:this.id + '-time'
,format:this.timeFormat || Ext.form.TimeField.prototype.format
,width:this.timeWidth
,selectOnFocus:this.selectOnFocus
Expand All @@ -140,8 +131,8 @@ Ext.ux.form.DateTime = Ext.extend(Ext.form.Field, {
,allowBlank: this.allowBlank
,msgTarget: this.msgTarget
,listeners:{
blur:{scope:this, fn:this.onBlur}
,focus:{scope:this, fn:this.onFocus}
blur:{scope:this, fn:this.onBlur}
,focus:{scope:this, fn:this.onFocus}
}
}, this.timeConfig);
this.tf = new Ext.form.TimeField(timeConfig);
Expand Down Expand Up @@ -176,7 +167,7 @@ Ext.ux.form.DateTime = Ext.extend(Ext.form.Field, {
var t;
if('below' === this.timePosition || 'bellow' === this.timePosition) {
t = Ext.DomHelper.append(ct, {tag:'table',style:'border-collapse:collapse',children:[
{tag:'tr',children:[{tag:'td', style:'padding-bottom:1px', cls:'ux-datetime-date'}]}
{tag:'tr',children:[{tag:'td', style:'padding-bottom:1px', cls:'ux-datetime-date'}]}
,{tag:'tr',children:[{tag:'td', cls:'ux-datetime-time'}]}
]}, true);
}
Expand Down Expand Up @@ -223,28 +214,29 @@ Ext.ux.form.DateTime = Ext.extend(Ext.form.Field, {

// create custom message targets for date and time fields
case 'under':
const dateMsgElId = `ux-datetime-date-msg-${this.itemId}`,
dateMsgWidth = Math.ceil(this.dateWidth - 30),
dateMsgEl = Ext.DomHelper.append(this.df.container, {
tag: 'div',
cls: 'x-form-invalid-msg',
style: `display: none; width: ${dateMsgWidth}px;`,
id: dateMsgElId
}),
timeMsgElId = `ux-datetime-time-msg-${this.itemId}`,
timeMsgWidth = Math.ceil(this.timeWidth - 30),
timeMsgEl = Ext.DomHelper.append(this.tf.container, {
tag: 'div',
cls: 'x-form-invalid-msg',
style: `display: none; width: ${timeMsgWidth}px;`,
id: timeMsgElId
})
const dateMsgElId = `ux-datetime-date-msg-${this.itemId}`,
dateMsgWidth = Math.ceil(this.dateWidth - 30),
dateMsgEl = Ext.DomHelper.append(this.df.container, {
tag: 'div',
cls: 'x-form-invalid-msg',
style: `display: none; width: ${dateMsgWidth}px;`,
id: dateMsgElId
}),
timeMsgElId = `ux-datetime-time-msg-${this.itemId}`,
timeMsgWidth = Math.ceil(this.timeWidth - 30),
timeMsgEl = Ext.DomHelper.append(this.tf.container, {
tag: 'div',
cls: 'x-form-invalid-msg',
style: `display: none; width: ${timeMsgWidth}px;`,
id: timeMsgElId
})
;
this.df.container.appendChild(dateMsgEl);
this.tf.container.appendChild(timeMsgEl);
this.df.msgTarget = dateMsgElId;
this.tf.msgTarget = timeMsgElId;
break;
// no default
}

// setup name for submit
Expand Down Expand Up @@ -523,7 +515,7 @@ Ext.ux.form.DateTime = Ext.extend(Ext.form.Field, {
return;
}
if ('number' === typeof val) {
val = new Date(val);
val = new Date(val);
}
else if('string' === typeof val && this.hiddenFormat) {
val = Date.parseDate(val, this.hiddenFormat);
Expand All @@ -534,8 +526,7 @@ Ext.ux.form.DateTime = Ext.extend(Ext.form.Field, {
this.setDate(val);
this.setTime(val);
this.dateValue = new Date(Ext.isIE ? val.getTime() : val);
}
else {
} else {
da = val.split(this.dtSeparator);
this.setDate(da[0]);
if(da[1]) {
Expand Down Expand Up @@ -594,22 +585,21 @@ Ext.ux.form.DateTime = Ext.extend(Ext.form.Field, {
* @private
* Updates the time part
*/
,updateTime:function() {
var t = this.tf.getValue();
if(t && !(t instanceof Date)) {
,updateTime: function() {
let t = this.tf.getValue();
if (t && !(t instanceof Date)) {
t = Date.parseDate(t, this.tf.format);
}
if(t && !this.df.getValue()) {
if (t && !this.df.getValue()) {
this.initDateValue();
this.setDate(this.dateValue);
}
if(this.dateValue instanceof Date) {
if(t) {
if (this.dateValue instanceof Date) {
if (t && !this.hideTime) {
this.dateValue.setHours(t.getHours());
this.dateValue.setMinutes(t.getMinutes());
this.dateValue.setSeconds(t.getSeconds());
}
else {
} else {
this.dateValue.setHours(0);
this.dateValue.setMinutes(0);
this.dateValue.setSeconds(0);
Expand Down