How can I prevent a user from typing more then 4 uinits of precision in a kendo numeric textbox

StackOverflow https://stackoverflow.com/questions/21125767

Вопрос

I have a requirement to allow a user to type a decimal with 4 units of precision. But only display 3. Is there a way to have the kendo-ui numerictextbox prevent more then 4 units of precision?

 $element.kendoNumericTextBox({
                     spinners: false,
                     culture: "en-US",
                     decimals: 4,
                     step: 0.01,
                     format: "n3"
                 });
Это было полезно?

Решение

I don't think there's a configuration option for that, but you can do something like this:

var numeric = $("#num").kendoNumericTextBox({
    spinners: false,
    culture: "en-US",
    decimals: 4,
    step: 0.01,
    format: "n3"
}).data("kendoNumericTextBox");

$(numeric.element).on("input", function (e) {
    var val = numeric.element.val();
    var parts;
    if (val.indexOf(".") !== -1) {
        parts = val.split(".");
        if (parts[1].length > 4) {
            numeric.element.val(val.substr(0, val.length - 1));
        }
    }
});

(demo)

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top