In Kendo, is it possible to change the configutation options of a Kendo NumericTextBox after it has been created?
I need a field to accept either a currency or a percentage, based on options set elsewhere. For simplicity, the below code shows the basic case of trying to change the placeholder, but I'll need to change the format, min, and max as well.
In my code, the original NumericTextBox is defined by Kendo MVC (but it could be changed to Kendo UI if there's a solution there).
Here is code in my ASP MVC view file:
<span>
@(Html.Kendo().NumericTextBoxFor(m => m.fieldName)
.Min(0)
.Spinners(false)
.Decimals(2)
.Format("c2")
.Placeholder("Enter amount")
.HtmlAttributes(new { @class = "input-amount", id = "kendo_ntb" })
)
</span>
To valiate I am accessing the object for the correct Kendo NumericTextBox, I run the below code (reference - How can I refresh value kendo numerictextbox?). As expected, it changes the value displayed in the field to "$999.00"
$("#kendo_ntb").data("kendoNumericTextBox").value("999");
I can access and change the options object as well; however, there is no change in how the NumericTextBox displays. In the Chrome console, I entered:
$("#kendo_ntb").data("kendoNumericTextBox").options["placeholder"] = "Enter Percentage"
$("#kendo_ntb").data("kendoNumericTextBox").options["placeholder"]
This returns "Enter Percentage" but placeholder displayed in the browser still reads "Enter Amount".
I was trying to following this example (How can I refresh value kendo numerictextbox?).
I tried the solution here with the same result: the options object change, but the browser display does not. No error is returned, but after running the below command, clicking on the form element no longer lets you enter a value.
$("#kendo_ntb").data("kendoNumericTextBox").setOptions({format: "#.#", decimals: 1, placeholder: "change please" });