Skip to content

Instantly share code, notes, and snippets.

@gregwiechec
Created December 7, 2023 13:44
Show Gist options
  • Save gregwiechec/3000f33992979e14364ff1201a846b9a to your computer and use it in GitHub Desktop.
Save gregwiechec/3000f33992979e14364ff1201a846b9a to your computer and use it in GitHub Desktop.
Date property
define([
"dojo/_base/declare",
"epi/shell/widget/DateTimeSelector",
"epi/shell/widget/DateTimeSelectorDropDown"
], function(
declare,
DateTimeSelector,
DateTimeSelectorDropDown
) {
function dateToString(date) {
if (!date){
return date;
}
// remove offset
const offset = date.getTimezoneOffset();
date = new Date(date.getTime() - (offset*60*1000));
return date.toISOString().split("T")[0];
}
var SimpleDateTimeSelector = declare([DateTimeSelector], {
buildRendering: function() {
this.inherited(arguments);
this.domNode.querySelector(".epi-timePickerWrapper").classList.add("dijitHidden");
},
_getValueAttr: function() {
var selectedDate = this.calendar.get("value");
if (!selectedDate) {
return null;
}
return dateToString(new Date(selectedDate.getFullYear(), selectedDate.getMonth(), selectedDate.getDate(), 0, 0, 0, 0));
}
});
return declare([DateTimeSelectorDropDown], {
popupClass: SimpleDateTimeSelector,
postMixInProperties: function () {
this.inherited(arguments);
this.constraints.datePattern = "yyyy-MM-dd";
this.constraints.selector = "date";
},
_getValueAttr: function () {
this.constraints.selector = "date";
var result = this.inherited(arguments);
return dateToString(result);
}
});
});
public class StandardPage : SitePageData
{
// ...
[ClientEditor(ClientEditingClass = "alloy/Editors/DateEditor")]
public virtual DateTime CustomDate { get; set; }
[ClientEditor(ClientEditingClass = "alloy/Editors/DateEditor")]
public virtual DateTime? CustomNullableDate { get; set; }
[ClientEditor(ClientEditingClass = "alloy/Editors/DateEditor")]
public virtual string CustomDateStr { get; set; }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment