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

DownList ValueTemplate insert problem

2 Answers 65 Views
DropDownList
This is a migrated thread and some comments may be shown as answers.
AP
Top achievements
Rank 1
Iron
Iron
Veteran
AP asked on 05 Aug 2015, 12:43 PM

I have an editor template set up, used in conjunction with a kendo grid.  It contains two drop-downlists which use templates and value templates to display images as well as text.

 The model contains an ID, which is a foreign key to a separate table, where the images are pulled from. The drop-down source controller creates the image path, and passes this to the drop-down list.

The mark up of one of the drop-downs  is:-

 

<p>
 
 
                    <span class="fieldlabel2">Trend:</span>@(Html.Kendo().DropDownList()
                      .Name("Trend")
                     .OptionLabel("Select trend")
          .DataValueField("ID")
          .DataTextField("ImageDescription")
 
        .DataSource(src => src.Read(rd => rd.Action("GetTrendsList", "MetricsInput")))
        .Template("#=ImagePath#<span style='margin-left:5px;'>#=ImageDescription #</span>")
        .ValueTemplate("#=ImagePath#<span style='margin-left:5px;'>#=ImageDescription #</span>")
                    )
                </p>

 

When used for editing existing records, the drop-downs work fine. However the insert button on the grid is used, a javascript error is thrown, complaining about 'ImagePath' being undefined.

 If the ValueTemplate is commented out, the drop-downs and the edit form work.

What do I need to do to fix this?

 

Thanks

2 Answers, 1 is accepted

Sort by
0
Accepted
Plamen Lazarov
Telerik team
answered on 07 Aug 2015, 12:46 PM

Hello,

The described behavior is expected because the used field in the template is not defined in the DataTextField. Thus the generated OptionLabel object does not contain it and respectively the Kendo Template throws exception. In order to use "ImagePath" in the template the OptionLabel should have the same structure as  "GetTrendsList". E.g.: 
.OptionLabel(new {
    ImagePath: "",
    ...
    ...
})

Let me know if I can be of a further assistance.

Regards,

Plamen Lazarov

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
AP
Top achievements
Rank 1
Iron
Iron
Veteran
answered on 07 Aug 2015, 01:05 PM

Thanks for the response.

However, I think you're getting slightly confused with the JavaScript syntax. I had to use the following

 

.OptionLabel(new {ImagePath="", ImageDescription="Select Status" })

Tags
DropDownList
Asked by
AP
Top achievements
Rank 1
Iron
Iron
Veteran
Answers by
Plamen Lazarov
Telerik team
AP
Top achievements
Rank 1
Iron
Iron
Veteran
Share this question
or