gisWeeper
gisWeeper

Reputation: 481

Kendo Ui - Check if Event exists

I'm using the Kendo Ui controls with .Net MVC. I want want to be able to check in javascript whether an event exists on a control. For example I declare a dialog window as below. In other places I declare the dialogs but do not add the refresh event. How do I check in javascript whether the refresh event exists or not?

      @(Html.Kendo().Window()
  .Title("Clone Existing Address")
  .Name("myDialog")
  .Modal(true)
  .Draggable()
  .Resizable()
  .Width(800)
  .Visible(false)
  .Actions(actions => actions
    .Minimize()
    .Maximize()
    .Close()
  )
  .Events(e => e.Refresh("refreshDialog"))
)

Example javascript: This dosnt work yet!!

function refreshEventExists() {
  var dialog = $("#myDialog").data("kendoWindow");
  if (dialog.refresh) {
    alert('Refreh event exists');
  }
  else {
    alert('Refreh event DOES NOT exists');
  }
}

Upvotes: 2

Views: 1625

Answers (1)

Lars Höppner
Lars Höppner

Reputation: 18402

You can inspect widget._events:

function numberOfHandlers(widget, eventName) {
    if (widget._events.hasOwnProperty(eventName)) {
        return widget._events[eventName].length;
    } 

    return 0;
}

var dialog = $("#dialog2").kendoWindow().data("kendoWindow");
dialog.bind("activate", function () {});

console.log(numberOfHandlers(dialog, "activate")); // logs "1" (one handler for the activate event)
console.log(numberOfHandlers(dialog, "refresh")); // logs "0" (no handlers for the refresh event

(demo)

Upvotes: 5

Related Questions