Is there an equivalent for jQuery.serializeArray in Kendo?

1 Answer 303 Views
Form Grid
Francis
Top achievements
Rank 1
Iron
Iron
Iron
Francis asked on 31 Jan 2022, 06:48 PM

Is there a built-in method like jQuery's serializeArray to pull the values for all the Kendo controls in a form? I recently found that the Html helper and Kendo CheckBox control creates hidden input tags for each CheckBox. The hidden fields are always set to "false". When I construct the model object after retrieving the values using serializeArray, the user input is overridden with the false values from the hidden fields. I cannot reject hidden fields as I have other hidden fields needed for my scenario. Some of our models are pretty big and it is tedious to construct each control in order to retrieve the user inputs.

The forms are mostly templates within a dialog invoked on Grid change event as the popup edit does not work with a custom template.

1 Answer, 1 is accepted

Sort by
1
Accepted
Stoyan
Telerik team
answered on 03 Feb 2022, 12:12 PM

Hi Francis,

Thank you for the explanation of the scenario at hand.

First, instead of a serializeArray method Telerik UI provides a Form Component in which you can access the whole Form Model like so:

var form = $("#form").data("kendoForm");
var dataItem = form._model;
Alternatively, you can get the state of a CheckBox using it check method.

Finally, I'd like to point out that a Grid which uses Popup Editing can have a Custom Template defined in its editable configuration property:

 .Editable(editable => {
            editable.Mode(GridEditMode.PopUp).TemplateName("EditTemplate");          
        }

Then you can define the EditTemplate.cshtml Partial View in the Views/Shared/EditorTemplates and it will be used as content for the popup.

I hope the information above is useful.

Regards,
Stoyan
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Francis
Top achievements
Rank 1
Iron
Iron
Iron
commented on 03 Feb 2022, 01:20 PM

Thank you, Stoyan.

The form component's _model would serve my purpose. Using the checkbox state would mean having to retrieve values for all the other form fields and would make my code huge because of my scenario.

As for the template, I recently found in another post in this forum and it works for me. Earlier I had used the DetailTemplate for the Grid thinking, the Edit and Create would use it. Instead it provided a row expansion form and not suitable for the number of fields I have. I had also used EditorTemplateId and it didn't work.

Tags
Form Grid
Asked by
Francis
Top achievements
Rank 1
Iron
Iron
Iron
Answers by
Stoyan
Telerik team
Share this question
or