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

我只是一个虾纸丫 提交于 2019-12-11 02:53:28

问题


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"
                 });

回答1:


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)



来源:https://stackoverflow.com/questions/21125767/how-can-i-prevent-a-user-from-typing-more-then-4-uinits-of-precision-in-a-kendo

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!