This is a migrated thread and some comments may be shown as answers.

Date, DateTime, Time Editor Templates

1 Answer 31 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
David
Top achievements
Rank 1
David asked on 14 Apr 2011, 03:49 PM

The Editor Templates for Date, DateTime, and Time included with the Q1 2011 (2011.1.315) release include the following method call:

.HtmlAttributes(new { id = ViewData.TemplateInfo.GetFullHtmlFieldName(string.Empty) + "_wrapper"})

This renders an invalid ID (under our model scenario, the ID ends up containing periods instead of underscores, since it is driving off the name attribute.

A dev I work with changed the editor templates to look like the following:

<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<DateTime?>" %>
<%
 string projectedGeneratedId = ViewData.TemplateInfo.GetFullHtmlFieldName(string.Empty).Replace('.', '_');
%>

<%= Html.Telerik().DatePicker()
  .Name(ViewData.TemplateInfo.GetFullHtmlFieldName(string.Empty))
  .HtmlAttributes(new { id = String.Format("{0}_wrapper", projectedGeneratedId) })
  .Value(Model > DateTime.MinValue? Model : DateTime.Today)
%>

Does that make sense?

David

1 Answer, 1 is accepted

Sort by
0
Accepted
Georgi Krustev
Telerik team
answered on 21 Apr 2011, 11:59 AM
Hello David ,

You are absolutely correct about this code snippet:

ViewData.TemplateInfo.GetFullHtmlFieldName(string.Empty) + "_wrapper"
GetFullHtmlFieldName method  will return full name which maybe will include points, which is not a valid value for the id attribute. The modification which you proposed will fixed this issue.

The only purpose to add id attribute with HtmlAttributes method was to style components in the online demos. In other words this id is not required in order to get working UI component. That is why the best solution is to avoid usage of HtmlAttributes method in the editor templates. In other words Editor Template for DateTime for instance will be this:
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<DateTime?>" %>
 
<%= Html.Telerik().DateTimePickerFor(m => m) %>
This Editor template is much more clean and readable.

As a gratitude of your feedback I have updated your Telerik points.


Best wishes,
Georgi Krustev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
General Discussions
Asked by
David
Top achievements
Rank 1
Answers by
Georgi Krustev
Telerik team
Share this question
or