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

AutoComplete shows undefined and null in template

3 Answers 450 Views
AutoComplete
This is a migrated thread and some comments may be shown as answers.
Toby
Top achievements
Rank 1
Toby asked on 13 May 2016, 04:11 PM

I have an AutoComplete control in a in a client template that uses the ToClientTemplate method

@(Html.Kendo().AutoComplete()
                    .Name("presenter")
                    .DataTextField("DisplayText")
                      .Filter("contains")
                      .MinLength(3)
                      .HtmlAttributes(new { style = "width:100%" })
                    .DataSource(source =>
                    {
                        source.Read(read =>
                        {
                            read.Action("Search", "People", new { SPHostUrl = ViewBag.SPHostUrl })
                                .Data("onPresenterAdditionalData");
                        })
                        .ServerFiltering(true);
                    })
                    .Template("<div><span class=\"k-state-default\">${ data.DisplayText }</span></div><div><span class=\"k-state-default\">${ data.Title }</span></div>")
                    .ToClientTemplate())

The controller is returning data and I have used Fiddler to make sure it is being sent to the browser.

The dropdown just shows "undefined" for DisplayText and "null" for Title.

The above control is in a template <script type="text/x-kendo-tmpl" id="documentDetailsTemplate"> and render using

var template = kendo.template($("#documentDetailsTemplate").html());

 

When I select one of the options, it displays the DisplayText of the selected option.

3 Answers, 1 is accepted

Sort by
0
Ivan Danchev
Telerik team
answered on 17 May 2016, 01:26 PM
Hello Toby,

Thank you for contacting Telerik support.

Since your scenario involves nesting Templates could you try using the following syntax, so that the expression is evaluated in the correct context: <span class=\"k-state-default\">\\#=  data.Title \\#</span>

Regards,
Ivan Danchev
Telerik
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 Feedback Portal and vote to affect the priority of the items
0
Toby
Top achievements
Rank 1
answered on 17 May 2016, 01:37 PM
Excellent, that fixed it. Thanks
0
Ivan Danchev
Telerik team
answered on 18 May 2016, 07:46 AM
Hello Toby,

Thank you for getting back to us. I am glad we were able to assist you and suggested template syntax works as expected.

Regards,
Ivan Danchev
Telerik
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 Feedback Portal and vote to affect the priority of the items
Tags
AutoComplete
Asked by
Toby
Top achievements
Rank 1
Answers by
Ivan Danchev
Telerik team
Toby
Top achievements
Rank 1
Share this question
or