November Happy Hour will be moved to Thursday December 5th.

How to show time portion only in content editor page in CMS12 ?

Vote:
 

I have a business requirement in one model that has time property but it shows both Date & Time as Calendar in the content editor in CMS12. 

I have read the article https://github.com/advanced-cms/time-property to fulfill my requirement. But this package is not compatible with CMS12. 

Anyone helps me out, How to achieve like time property in CMS12? 

Thanks

Vijay

#267322
Nov 24, 2021 15:23
Vote:
 

Create a class called TimeEditorDescriptor.cs

    [EditorDescriptorRegistration(TargetType = typeof(DateTime?), UIHint = "TimeOnly")]
    public class TimeEditorDescriptor : EditorDescriptor
    {
        public override void ModifyMetadata(ExtendedMetadata metadata, IEnumerable<Attribute> attributes)
        {
            ClientEditingClass = "dijit/form/TimeTextBox";
            base.ModifyMetadata(metadata, attributes);
        }
    }

Use this hint on properties such as the following

        [Display(
            GroupName = SystemTabNames.Content,
            Order = 2,
            Name = "Time")]
        [UIHint("TimeOnly")]
        public virtual DateTime? StartDate { get; set; }
#267324
Nov 24, 2021 15:41
Vote:
 

 It resolved my issue. Thanks, Scott Reed for the quick response. It's working as expected. 

I have the other question on displaying time, How to display the time format like HH:MM instead of hh:mm tt ? What kind of Attribute or Property need to be set in code?

#267326
Nov 24, 2021 17:06
Vote:
 

MM is month? If you want 24 hour and minutes that's HH:mm

Try changing TimeEditorDescriptor to

    [EditorDescriptorRegistration(TargetType = typeof(DateTime?), UIHint = "TimeOnly")]
    public class TimeEditorDescriptor : EditorDescriptor
    {
        public override void ModifyMetadata(ExtendedMetadata metadata, IEnumerable<Attribute> attributes)
        {
            ClientEditingClass = "dijit/form/TimeTextBox";
            EditorConfiguration["constraints"] = new Dictionary<string, string>
            {
                { "timePattern", "HH:mm" }
            };
            base.ModifyMetadata(metadata, attributes);
        }
    }
#267327
Nov 24, 2021 17:50
Vote:
 

Thanks, Scott Reed. It's working as expected.

#267328
Nov 24, 2021 17:56
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.