Including custom HTML in Form

1 Answer 29 Views
Form
Chris
Top achievements
Rank 1
Iron
Iron
Iron
Chris asked on 26 Feb 2025, 02:48 PM

Hi

I have a form component, and ideally I'd like to embed some custom HTML within it alongside one of the fields.

For example pseudo code for if this sort of thing was possible :

items.Add()
.Field(f => f.Task.StartDate)
.Label(l => l.Text("Call Date"))
.Editor(e =>
{
	e.DateTimePicker()
	.Size(ComponentSize.Small)
	.Format("{0:dd/MM/yyyy HH:mm}")
	.Min(DateTime.Now)
	.DateInput();
});

items.Add()
.ClientTemplate(<ul><li><a href="test1">A Link</a></li><li><a href="test2">Another Link</a></li></ul>);
How do I achieve injecting my own HTML into the form layout please?

1 Answer, 1 is accepted

Sort by
0
Mihaela
Telerik team
answered on 03 Mar 2025, 09:51 AM

Hello Chris,

You can insert custom HTML along with the field's editor as per any of the following approaches:

  • Use the EditorTemplateId() option to set the desired editor:
items.Add()
.Field(f => f.Task.StartDate)
.Label(l => l.Text("Call Date"))
.EditorTemplateId("dtpEditor");

<script type="text/x-kendo-template" id="dtpEditor">
  <ul><li><a href="test1">A Link</a></li><li><a href="test2">Another Link</a></li></ul>
  @(Html.Kendo().DateTimePicker()
        .Name("Task.StartDate")
	.Size(ComponentSize.Small)
	.Format("{0:dd/MM/yyyy HH:mm}")
	.Min(DateTime.Now)
	.DateInput();
   )
</script>
  • Use the EditorTemplateView() option to insert the editor and the HTML through a Partial View:
items.Add()
.Field(f => f.Task.StartDate)
.Label(l => l.Text("Call Date"))
.EditorTemplateView(Html.Partial("_FormEditor"));

//~Views/Home/_FormEditor.cshtml
@{
    Layout = null;
}
<ul><li><a href="test1">A Link</a></li><li><a href="test2">Another Link</a></li></ul>
@(Html.Kendo().DateTimePicker()
        .Name("Task.StartDate")
        .HtmlAttributes(new { id = "Task_StartDate"})
	.Size(ComponentSize.Small)
	.Format("{0:dd/MM/yyyy HH:mm}")
	.Min(DateTime.Now)
	.DateInput();
)

Regards,
Mihaela
Progress Telerik

Enjoyed our products? Share your experience on G2 and receive a $25 Amazon gift card for a limited time!

Chris
Top achievements
Rank 1
Iron
Iron
Iron
commented on 03 Mar 2025, 10:17 AM

Many thanks - I have used the EditorTemplateId option.
Tags
Form
Asked by
Chris
Top achievements
Rank 1
Iron
Iron
Iron
Answers by
Mihaela
Telerik team
Share this question
or