Cancel Dropdown list change event

4 posts, 0 answers
  1. Arun
    Arun avatar
    4 posts
    Member since:
    Jul 2012

    Posted 24 Jul 2012 Link to this post

    Hi how do i cancel the dropdown change event?
    i am doing a user conformation on dropdown change event. if the user confirm no then the dropdown selected value should go back to its old value. i tried return false but didnt work. 

    $("#myDropdown").data("kendoDropDownList");
    .bind("change", function (e) {
    if(!confirm('warning'))
    return false;
    }
    thanks for your help Arun
  2. Arun
    Arun avatar
    4 posts
    Member since:
    Jul 2012

    Posted 27 Jul 2012 Link to this post

    seems we cannot cancel the change event.  To achieve the desired functionality i had to bind to 'select' event and then do 
       e.preventDefault();
    
     	 
             
    ('#myDropdown').bind("select", function (e) {
               var data = this.dataItem(e.item.index());
                var current = this.value();  // this will have the old selected value
                var selectedType = data.Code; //this will have the new selected value
    }

    please feel to correct me if i am wrong :-) thanks, Arun
  3. Kendo UI is VS 2017 Ready
  4. Elias
    Elias avatar
    1 posts
    Member since:
    Oct 2012

    Posted 15 Nov 2012 Link to this post

    You can't cancel the onChange event, but you can cancel the onSelect event. Call the preventDefault() function and it will cancel the event.

    function onSelect(e) {
        e.preventDefault();
    }

    -- or --
    ('#myDropdown').bind("select", function (e) {
        e.preventDefault();
    }
  5. Tayger
    Tayger avatar
    61 posts
    Member since:
    Jan 2015

    Posted 21 Mar in reply to Arun Link to this post

    Thank you, works well also on my side... In case of having an optionLabel in dropownlist you have to add +1 to the index, else its always shifted by 1:

    var data = this.dataItem(e.item.index()+1);

    That shouldn't be since the optionLabel is no more an element of DOM and dropdownlist. 

Back to Top
Kendo UI is VS 2017 Ready