So I wanted to know if there was an easier way to find the current state of the toggle button. I used a global variable defined in the scope of the .js file I am using.
var isSelected = false.
Then for extra safety and really embarrassingly enough we just kind of blindly follow this pattern, we put this variable in a kendo.observable:
function initControls() {
//More initialization stuff before...
_view = kendo.observable({
intervalList: _intervalList,
layoutDataList: _layoutDataList,
noCustoms: _noCustoms,
isSelected: _isSelected, //<--------[ADDED]
})
)
//More initialization code after
}
//Percent button:
$("#my-toggle-btn").kendoToggleButton({
icon: "null", // using Font Awesome for an icon.
enable: true,
selected: false,
togglable: true,
click: function () {
// on the click change current state of the percentSelected:
_view.set("isSelected", !_view.get("isSelected"));
let perSelected = _view.get("isSelected");
console.log("percentSelected toggled to: " + perSelected);
if (perSelected) {
console.log("...button should be BLUE.");
} else {
console.log("...button should be GREY.");
}
}
});
var number = $("#numberInput").data("kendoNumericTextBox").value();
// Detect if percentage toggle is active -- GREY not selected and BLUE == selected.
var isPercent = _view.get("isSelected");
//... later in the code this is evaluated like:
//If the percent toggle button in true/BLUE then convert.
//Ergo...modify to make the number in the input a percent value 30 is percent then it needs to be converted to .30.
var modifier = isPercent ? val * (number / 100) : number;//ternary operator.
// then later in the code the percentage value or the non-percentage value is inserted into a simple
// mathematical formula that loops through an array of numeric values...
Again the toggle button in question simple allows the user to convert an numeric input to a percentage value of a number operated on (add, subtract, multiply)... ergo secondary color = BLUE, then number is a percent, if its the initial or color = GRAY then the number is just it's face value. I couldn't capture any examples of a real use case. I later found the onToggle event handler and yeah you can read the current value thorugh that...but thought it was overkill...still I am confused on how to use it to flag options...or correct usage.