Hi!
I use a lot of forms (created using HtmlHelper) inside templates used by various other elements (mainly inside TileLayouts).
e.g.:
public record SettingsViewModel
{
[DataType(DataType.Password)]
public string Password { get; set; } = null!;
}
<script id="settings-template" type="text/x-kendo-template">
@(Html.Kendo().Form<settingsViewModel>()
.Name("settingsForm")
.FormData(Model.Settings)
.Layout("grid")
.Grid(g => g.Cols(2).Gutter(5))
.HtmlAttributes(new { method = "POST", style = "width: 100%;" })
.Validatable(v =>
{
v.ValidateOnBlur(false);
v.ValidationSummary(true);
})
.Items(items =>
{
items.Add().Field(f => f.Password).Label("Password");
})
.ToClientTemplate()
@* .ToString()
.Replace("#", "\\#") *@
)
</script>
<div class="k-d-flex-col k-justify-content-center">
@(Html.Kendo().TileLayout()
.Name("settings")
.Columns(5)
.RowsHeight("auto")
.Containers(c =>
{
...
c.Add().BodyTemplateId("settings-template").ColSpan(4).RowSpan(1);
...
})
)
</div>
Many of these forms requires to accept text boxes (like passwords) which should accept "#" in their content.
Saving works perfect but when rendering the Form I always get an exception. Please see below error:
Uncaught Error: Invalid template:'
<form id="settingsForm" method="POST" name="settingsForm" style="width: 100%;"></form><script>kendo.syncReady(function(){jQuery("\#settingsForm").kendoForm({"validatable":{"validateOnBlur":false,"validationSummary":{}},"formData":{"Password":"bla#bla","Id":0},"layout":"grid","grid":{"cols":2,"gutter":5},"serverErrors":{},"items":[{"field":"Password","label":{"text":"Password"},"editorOptions":{},"validation":{"data-val":"true","data-val-required":"The Password field is required.","type":"password"},"shouldRenderHidden":true}]});});<\/script>
' Generated code:'var $kendoOutput, $kendoHtmlEncode = kendo.htmlEncode;with(data){$kendoOutput='\n <form id="settingsForm" method="POST" name="settingsForm" style="width: 100%;"></form><script>kendo.syncReady(function(){jQuery("#settingsForm").kendoForm({"validatable":{"validateOnBlur":false,"validationSummary":{}},"formData":{"Password":"bla';bla","Id":0},"layout":"grid","grid":{"cols":2,"gutter":5},"serverErrors":{},"items":[{"field":"Password","label":{"text":"Password"},"editorOptions":{},"validation":{"data-val":"true","data-val-required":"The Password field is required.","type":"password"},"shouldRenderHidden":true}]});});<\/script>
;$kendoOutput+=;}return $kendoOutput;'
at Object.compile (kendo.all.js:322401:19)
at init._initContainers (kendo.all.js:322401:19)
at new init (kendo.all.js:322401:19)
at HTMLDivElement.<anonymous> (kendo.all.js:322401:19)
at Function.each (jquery.min.js:2:2898)
at n.fn.init.each (jquery.min.js:2:846)
at e.fn.<computed> [as kendoTileLayout] (kendo.all.js:322401:19)
.......
Any idea how to fix that on the client-side (and not need to escape each property I want to accept "#" at server-side) ?
Thanks