This project is read-only.

Using datetime field editor for a custom part

Topics: Customizing Orchard, Writing modules
Nov 15, 2012 at 6:50 PM


I'm new to module creation.

I was wondering if I can reuse the editor in DateTime.Edit.cshtml as editor for my Part.

Part is something like follow.


    public class ProfilePart : ContentPart<ProfilePartRecord> {
        public string FirstName {
            get { return Record.FirstName; }
            set { Record.FirstName = value; }
        public string Surname {
            get { return Record.Surname; }
            set { Record.Surname = value; }
        public DateTime? BirthDate
            get { return Record.BirthDate == DateTime.MinValue ? new DateTime(1900,1,1) : Record.BirthDate; }
            set { Record.BirthDate = value.HasValue ? value.Value : new DateTime(1900, 1, 1); }

How can decorate the BirthDate field so that it uses the alreaydy present in Orchard Date editor?



Nov 15, 2012 at 7:57 PM

Could you just add a dateTime field directly to the part or type that you're creating through the admin editor?

Nov 16, 2012 at 8:30 AM

Hi, thanks for reply.

Indeed the code sample is a small part of a bunch of fields (more than 20) and I want to distribute as a single module.

The question is indeed:

how I may use the work already done with date field and (in jquery module) with all localization stuff for datepicker?

I can for sure create a datetime template in my module and use that, I was wondering if I really need to do that or Orchard let me reuse some stuff that is already done.


Nov 16, 2012 at 6:12 PM

Worst case, you can look at the code for the date field and do the same.