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

Get (custom) value on change event

2 Answers 2495 Views
DropDownList
This is a migrated thread and some comments may be shown as answers.
Tayger
Top achievements
Rank 1
Iron
Tayger asked on 12 Aug 2016, 10:22 AM

Hello

I have a series of Dropdownlists in a mask that all work fine so far. They all have a select event for some background tasks. For programmatically rebuilding these Dropdownlists (in case the user wants to make some changes later on) I rebuild/display first all the Dropdownlists, fill them up by the attached datasources and then set the pre-set value (previously done by user) by triggering the specific select event on the specific Dropdownlist (cascading). But triggering the select event programmatically I got an error: 

TypeError: undefined is not an object (evaluating 'e.item.index')

This error is caused inside the select event (on Dropdownlist) by this line: 

var objectTargetId = this.dataItem(e.item.index()).objectTargetId;

After some investigations I found out that it would be easier to me to switch to change event inside Dropdownlist. The error causing line causes also the same error in change event, so I replaced the line by:

var objectTargetId = this.value();

Works fine so far. 

One of the Dropdownlist has an additional custom field: 

$("#objecttarget"+conditionNumber).kendoDropDownList({
  dataValueField: "objectTargetId",   
  dataTextField: "objectTargetText",
  dataTypeField: "objectTargetType",    
  change: function(e) { ...

I wonder now how I can access the value of "dataTypeField" inside the change event of this Dropdownlist? Previously (select event) it worked that way: 

this.dataItem(e.item.index()).objectTargetType;

My current solution looks like this: 

var selIndex = $("#objecttarget"+conditionNumber).data("kendoDropDownList").selectedIndex;
var objectTargetType = $("#objecttarget"+conditionNumber).data("kendoDropDownList").options.dataSource._view[selIndex].objectTargetType;

That seems to work too but I don't feel well going through the specific structure, that might change in future. Is there an easier, more official way to get the value of a custom field (in my case "objectTargetType"?

Regards

 

2 Answers, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 16 Aug 2016, 07:03 AM
Hi,

You can use the dataItem method without parameter to get the selected item and the custom value - example.

Regards,
Daniel
Telerik by Progress
 
Get started with Kendo UI in days. Online training courses help you quickly implement components into your apps.
 
0
Tayger
Top achievements
Rank 1
Iron
answered on 17 Aug 2016, 08:32 PM
Excellent, thank you! Your example showed me the right way. 
Tags
DropDownList
Asked by
Tayger
Top achievements
Rank 1
Iron
Answers by
Daniel
Telerik team
Tayger
Top achievements
Rank 1
Iron
Share this question
or