Don't miss out Virtual Happy Hour today (April 26).

Try our conversational search powered by Generative AI!

Custom renderer for PropertyDateControl doesn't work

Vote:
 

I've tried to create a "DateFormat"-renderer where you can specify a format for a date property (duh :)).

Nothing strange at all really:

[TemplateDescriptor(TagString = "FormatDate")]
public class FormatDate : PropertyDateControl, IRenderTemplate<DateTime>
{    
public override void CreateDefaultControls()
{ // Code here... } }

But if I change the class to inherit from PropertyStringControl and IRenderTemplate<string> instead, it works for string properties.
Anyone else had this problem?
#72643
Jun 25, 2013 13:15
Vote:
 

It sounds like there could be something wrong with your Property. Can you explain how your Property is created? Also have a look in Admin mode to check whether your Property accually is stored as a DateTime.

Also, personally I would prefer to use PropertyControlBase if you only want to render for visitor and not change the behaviour for editors.

See http://world.episerver.com/Blogs/Linus-Ekstrom/Dates/2012/10/Custom-renderers-for-properties/

#72644
Jun 25, 2013 13:47
Vote:
 

It's not a custom property, It's EPiServers default Date property.
I can agree with you but in this case, the date is to be formatted when the editor is editing too.

I took that exact code and it works for string properties but not for the date property. Hmm. Any more ideas?

#72645
Jun 25, 2013 13:56
Vote:
 

Hi, I meant how you add the Property to your Page Type? Manually or by code?

#72647
Jun 25, 2013 15:00
Vote:
 

By code ofc. :)

[Searchable(false)]
		[Display(
			Name = "Datum",
			Order = 10
		)]
		public virtual DateTime Date { get; set; }

    

#72648
Edited, Jun 25, 2013 15:01
Vote:
 

Could you give what the code looks like?
Also, have a look in Admin mode at the Property to tell whether EPiServer have interpreted your code and updated the database correctly. When the behaviour on Properties isn't what I expect, I usually find some clues here.

#72649
Jun 25, 2013 15:03
Vote:
 

Ah replied before I saw your code.

This seems to look correct. Now is the questions if EPiServer has the correct values in the database?

#72650
Jun 25, 2013 15:09
Vote:
 

Yes, I checked that too and the property definition type is 5, which is Date.

This must be a bug?

#72651
Edited, Jun 25, 2013 15:15
Vote:
 

Where are you telling the property to use the renderer tagged "FormatDate"? Are you adding a tag to the property webcontrol or propertyFor call?

#72653
Jun 25, 2013 16:38
Vote:
 
<episerver:property propertyName="Date" customTagName="span" cssClass="date" runat="server">
	<renderSettings tag="FormatDate" />
</episerver:property>
#72654
Jun 25, 2013 16:39
Vote:
 

I can't replicate having an EditorDescriptor for a DateTime either.

I've tried creating classes inheriting PropertyDateControl and PropertyControlBase<DateTime>.

It seems like the TemplateResolver doesn't register these Templates correctly?

Should something more be specified on the TemplateDescriptor?

#72655
Jun 25, 2013 17:02
Vote:
 

Hi!

I have reproduced the issue, created a bug and also made a fix since it was a quite small change. The bug for further tracking is:

Bug #101219: It's not possible to add custom renderers to some built in property types

#72839
Jul 01, 2013 15:28
Vote:
 

Lovely! :)

#72841
Jul 01, 2013 16:00
Vote:
 

Hi Linus,

This is fixed in the release of 7.5 today?

#78816
Dec 03, 2013 22:31
Vote:
 

Yes, this bug should be fixed in the 7.5 release.

#78832
Dec 04, 2013 9:57
This thread is locked and should be used for reference only. Please use the Episerver CMS 7 and earlier versions forum to open new discussions.
* 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.