Form with MultiSelect editor does not submit selected values in the MultiSelect.
The Kendo Form should include native ListBox editor support including joining and swapping items between two ListBox's using ConnectWith.
To use a ListBox in the Kendo Form currently requires a custom editor which is overly complex.
When a Telerik UI for ASP.NET Core MultiSelect is used in a Form, a JS error is thrown:
jquery.min.js:2 Uncaught Error: Syntax error, unrecognized expression: #
at Function.se.error (jquery.min.js:2)
at se.tokenize (jquery.min.js:2)
at se.select (jquery.min.js:2)
at Function.se [as find] (jquery.min.js:2)
at S.fn.init.find (jquery.min.js:2)
at new S.fn.init (jquery.min.js:2)
at S (jquery.min.js:2)
at Object.data ((index):24)
at init.setup (kendo.all.js:6596)
at init.read (kendo.all.js:6574)
The issue occurs when using jQuery 3.6.0, but is absent with jQuery v 1.12.4
@(Html.Kendo().Form<FormViewModel>()
.Name("exampleForm")
.HtmlAttributes(new { action = "Items", method = "POST" })
.Validatable(v =>
{
v.ValidateOnBlur(true);
v.ValidationSummary(vs => vs.Enable(true));
})
.Items(items =>
{
items.Add()
.Field(f => f.MultiSelect)
.Label(l => l.Text("MultiSelect:"))
.Editor(e =>
{
e.MultiSelect()
.HtmlAttributes(new { })
.Placeholder("Select...")
.DataTextField("ProductName")
.DataValueField("ProductID")
.HtmlAttributes(new { style = "width:100%" })
.Height(520)
.DataSource(source =>
{
source.Read(read =>
{
read.Action("Items_GetProducts", "Form");
})
.ServerFiltering(true);
});
});
})
)
public class FormViewModel
{
public List<ProductViewModel> MultiSelect { get; set; }
}
Runnable sample available in ticket 1540812
JavaScript error should not be thrown.
The Form TagHelper does not provide support for hidden fields, similar to the HtmlHelper.
The Form TagHelper does not allow similar built-in configuration:
.Items(i =>
{
i.Add()
.Field(f => f.UserID)
.Editor(editor => editor.Hidden());
})
The Form TagHelper should support hidden inputs.
Similar result can be achieved by setting the editor-handler
attribute, creating a hidden input and setting an empty label:
<form-items>
<form-item field="UserID" editor-handler="hiddenEditor" >
<item-label text=" " />
</form-item>
</form-items>
<script>
function hiddenEditor(container, options) {
$('<input type="hidden" data-bind="value: ' + options.field + '" name="' + options.field + '"/>')
.appendTo(container);
}
</script>
Form TagHelper does not expose a ValidationSummary tag.
The Form TagHelper's exposes only a validation-summary attribute instead of a validation-summary tag which prevents adding options such as: Container, Enable, Template, and more.
In comparison to the HTML Helper .ValidationSummary() API configuration which allows the following:
.Validatable(v =>
{
v.ValidationSummary(validationSummary => {
validationSummary.Enable(true);
validationSummary.TemplateId("someTemplate");
validationSummary.Container("myContainer");
});
})
It would be a good idea to consider altering the current validation-summary
attribute into a standalone tag helper. However, this will inevitably lead to a breaking change.
The FormItemBuilder exposes an EditorTemplateView method which allows a view to represent the item and provides the entire modal to the view.
As the elements available to forms are limited to those hard coded by Telerik and whilst extension methods can be employed to expand this limitation slightly, the ability to create a context specific view would be ideal
The current implementation looks like this
Html.Kendo().Form<Model>()
.Items(items =>
{
items.AddGroup("Test", 1, 10)
.Items(i =>
{
i.Add().Field(x => x.Username)
i.Add().Field(x => x.Password).EditorTemplateView(Html.Partial("MyView"))
}
);
})
In this example, the entire model is provided into MyView.
I suggest adding an EditorTemplateFor that uses the lamda expression provided in the Field() method such as
Html.Kendo().Form<Model>()
.Items(items =>
{
items.AddGroup("Test", 1, 10)
.Items(i =>
{
i.Add().Field(x => x.Username)
i.Add().Field(x => x.Password).EditorTemplateViewFor(Html.Partial("MyView"))
}
);
})
### Bug report
When loading an editor through a partial View using EditorTemplateView(await Html.PartialAsync("PartialViewName")), the following error occurs:
The 'await' operator can only be used within an async lambda expression. Consider marking this lambda expression with the 'async' modifier.
### Reproduction of the problem
@(Html.Kendo().Form<UserViewModel>()
.Name("myForm")
.Items(items =>
{
items.Add().Field(f => f.Username).EditorTemplateView(await Html.PartialAsync("PartialViewName"));
})
)
### Expected/desired behavior
The EditorTemplateView() must accept Html.PartialAsync("PartialViewName").
### Environment
* **Telerik UI for ASP.NET Core version: 2024.4.1112
* **Browser: [all]