Get (custom) value on change event

3 posts, 0 answers
  1. Tayger
    Tayger avatar
    55 posts
    Member since:
    Jan 2015

    Posted 12 Aug Link to this post


    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: 

      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: 


    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"?



  2. Daniel
    Daniel avatar
    2109 posts

    Posted 16 Aug Link to this post


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

    Telerik by Progress
    Get started with Kendo UI in days. Online training courses help you quickly implement components into your apps.
  3. Tayger
    Tayger avatar
    55 posts
    Member since:
    Jan 2015

    Posted 17 Aug in reply to Daniel Link to this post

    Excellent, thank you! Your example showed me the right way. 
Back to Top