Enable/Disable multiple buttons

2 Answers 2633 Views
Button
Grant
Top achievements
Rank 3
Iron
Iron
Veteran
Grant asked on 27 Jul 2016, 02:50 PM

Hi,

I have a table containing 28 dynamically generated KendoUI buttons that represent a 28 day cycle. Im trying to enable and disable them all at once, but only the first button is being affected. Please advise.

//Inialize ALL 'day selection' buttons
$("#table-frequencyWindow-daySelection").find("button.dayButton").kendoButton({
  enable: false
});
 
//Inialize Frequency Selecter as kendo Drop Down List
$("#select-frequencyWindow-frequency").kendoDropDownList({
  change: function(e) {
    var daySelectionTable = $("#table-frequencyWindow-daySelection");
    console.log(daySelectionTable.find("button.dayButton").length) //Prints "28"
 
    if (this.value() == "") {
      daySelectionTable.find("button.dayButton").data("kendoButton").enable(false);
 
    } else {
      daySelectionTable.find("button.dayButton").data("kendoButton").enable(true);
    }
  }
});

2 Answers, 1 is accepted

Sort by
0
Accepted
Misho
Telerik team
answered on 02 Aug 2016, 07:05 AM
Hi,

You can enable/disable all buttons using jQuery find, which will return an object of elements, together with jQuery each method in the following manner:

$("#example").find(".k-button").each(function(index)
  {
     $(this).data("kendoButton").enable(false);
  }
)
http://dojo.telerik.com/@parvanov/eJEZa/9

Regards,
Misho
Telerik by Progress
 
Get started with Kendo UI in days. Online training courses help you quickly implement components into your apps.
 
Dany
Top achievements
Rank 1
commented on 10 Aug 2018, 04:24 PM

Is there a way to get the enabled state from the KendoButton instance?
Grant
Top achievements
Rank 3
Iron
Iron
Veteran
commented on 13 Aug 2018, 06:43 AM

Sure there is. You can read it from the 'options' attribute of the kendoButton Instance.

var enabled = kendoButtonInstance.options.enable;

Dojo here: https://dojo.telerik.com/OZUTOfUl

 

0
Misho
Telerik team
answered on 29 Jul 2016, 08:34 AM
Hi,

You can use the Kendo button enable() method to control the button Enable/Disable state.
For multiple buttons you can iterate over the buttons in a loop and set the desired Enable or Disable state according to your needs. Here is a simple example showing the approach:
http://dojo.telerik.com/@parvanov/eJEZa/8


Regards,
Misho
Telerik by Progress
 
Get started with Kendo UI in days. Online training courses help you quickly implement components into your apps.
 
Grant
Top achievements
Rank 3
Iron
Iron
Veteran
commented on 29 Jul 2016, 10:30 AM

Thanks Misho, 

This is the solution I have also arrived at and have already implemented it with success. Initially I was hoping there would be a way to enable/disable all the buttons at once instead of iterating over each one every time, so I let the question stand. 

As explained in my question though, when I try to enable/disable the buttons using the previous code, only the first KendoButton in the series is affected. Can you think of any reason why the others would be ignored, just out of curiosity?

Thanks Again, 

Grant

Tags
Button
Asked by
Grant
Top achievements
Rank 3
Iron
Iron
Veteran
Answers by
Misho
Telerik team
Share this question
or