Skip to content

Instantly share code, notes, and snippets.

@gregwiechec
Last active August 29, 2015 14:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gregwiechec/6fa6dd40c92d00ce3e77 to your computer and use it in GitHub Desktop.
Save gregwiechec/6fa6dd40c92d00ce3e77 to your computer and use it in GitHub Desktop.
EPiServer - Nullable date property
define([
"dojo/_base/declare",
"dojo/_base/lang",
"dojo/dom-style",
"dojo/dom-construct",
"dojo/keys",
"dojo/on",
"epi/shell/widget/DateTimeSelectorDropDown"
],
function(
declare,
lang,
domStyle,
domConstruct,
keys,
on,
DateTimeSelectorDropDown
) {
return declare("alloy.editors.nullableDateTimeSelectorDropDown", [DateTimeSelectorDropDown], {
clearLinkNode: null,
postMixInProperties: function() {
this.inherited(arguments);
this.clearNode = domConstruct.create("a", { innerHTML: "Clear value", title: "CTRL + DEL" });
domStyle.set(this.clearNode, {
'float': 'right',
'margin': '-20px -90px 0 0',
'cursor': 'pointer'
});
},
postCreate: function() {
this.inherited(arguments);
on(this.clearNode, "click", lang.hitch(this, this._clearValue));
on(this, "keypress", function (evt) {
if (evt.keyCode == keys.DELETE && evt.ctrlKey) {
this._clearValue();
}
});
dojo.place(this.clearNode, this.domNode);
},
_clearValue: function() {
this.set("value", null);
},
_setReadOnlyAttr: function(readOnly) {
this.inherited(arguments);
if (this.clearNode != null) {
domStyle.set(this.clearNode, "display", "none");
}
domStyle.set(this.clearNode, "display", readOnly ? "none" : "block");
}
});
});
using System;
using EPiServer.Shell.ObjectEditing.EditorDescriptors;
namespace EpiServerThumbnail.Business.EditorDescriptors
{
[EditorDescriptorRegistration(TargetType = typeof(DateTime?), UIHint = UIHint)]
public class NullableDateEditorDescriptor : DateTimeEditorDescriptor
{
public const string UIHint = "nullable-date";
public NullableDateEditorDescriptor()
{
this.ClientEditingClass = "alloy.editors.nullableDateTimeSelectorDropDown";
}
}
}
[Display(Name="Nullable date", GroupName = SystemTabNames.Content, Order = 340)]
[UIHint(NullableDateEditorDescriptor.UIHint)]
public virtual DateTime? NullableDate { get; set; }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment