最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to disable dots on Kendo UI NumericTextBox? - Stack Overflow

programmeradmin2浏览0评论

I need to make a numeric field only integer, so that the field does not accept decimals. I would not even like the field to approximate, simply not accepting points or mas.

Based on the culture, it accepts the numeric separator (eg EN is the point, IT is the ma)

Here is the code I tried

$("#numerictextbox").kendoNumericTextBox({
     culture: "en-US",
     step: 500,
     spinners: false,
     format: "#",
     decimals: 0
});
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8"/>
    <title>Kendo UI Snippet</title>

    <link rel="stylesheet" href=".3.1023/styles/kendomon.min.css"/>
    <link rel="stylesheet" href=".3.1023/styles/kendo.rtl.min.css"/>
    <link rel="stylesheet" href=".3.1023/styles/kendo.silver.min.css"/>
    <link rel="stylesheet" href=".3.1023/styles/kendo.mobile.all.min.css"/>

    <script src=".12.4.min.js"></script>
    <script src=".3.1023/js/kendo.all.min.js"></script>
 <script src=".3.1023/js/cultures/kendo.culture.en-US.min.js?bust=v21"></script>
</head>
<body>
  
<input id="numerictextbox" />
</body>
</html>

I need to make a numeric field only integer, so that the field does not accept decimals. I would not even like the field to approximate, simply not accepting points or mas.

Based on the culture, it accepts the numeric separator (eg EN is the point, IT is the ma)

Here is the code I tried

$("#numerictextbox").kendoNumericTextBox({
     culture: "en-US",
     step: 500,
     spinners: false,
     format: "#",
     decimals: 0
});
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8"/>
    <title>Kendo UI Snippet</title>

    <link rel="stylesheet" href="https://kendo.cdn.telerik./2019.3.1023/styles/kendo.mon.min.css"/>
    <link rel="stylesheet" href="https://kendo.cdn.telerik./2019.3.1023/styles/kendo.rtl.min.css"/>
    <link rel="stylesheet" href="https://kendo.cdn.telerik./2019.3.1023/styles/kendo.silver.min.css"/>
    <link rel="stylesheet" href="https://kendo.cdn.telerik./2019.3.1023/styles/kendo.mobile.all.min.css"/>

    <script src="https://code.jquery./jquery-1.12.4.min.js"></script>
    <script src="https://kendo.cdn.telerik./2019.3.1023/js/kendo.all.min.js"></script>
 <script src="https://kendo.cdn.telerik./2019.3.1023/js/cultures/kendo.culture.en-US.min.js?bust=v21"></script>
</head>
<body>
  
<input id="numerictextbox" />
</body>
</html>

Here you can find the link to dojo with the example of Italian culture, in this case it blocks the ma

Share Improve this question edited Oct 28, 2019 at 10:28 i.signori asked Oct 28, 2019 at 10:11 i.signorii.signori 5953 silver badges16 bronze badges 3
  • 1 Have you tried changing the format to "{0:n0}"? You can also try "{0:#.##}" if you find that "{0:n0}" doesn't always get rid of the decimal separator. – Daniel Attfield Commented Oct 28, 2019 at 10:23
  • They eliminate the decimal separator, but the problem remains. I would not like the new value to be approximated (eg 3.9 bees 4) – i.signori Commented Oct 28, 2019 at 10:32
  • I wouldn't want them to be able to add it, now as you can try in the examples, it's possible. But I would like to have only integer number, if possible not let the user to insert a separator. – i.signori Commented Oct 28, 2019 at 10:41
Add a ment  | 

1 Answer 1

Reset to default 6

Try using the restrictDecimals configuration option.

$("#numerictextbox").kendoNumericTextBox({
    culture: "en-US",
    step: 500,
    spinners: false,
    format: "#",
    decimals: 0,
    restrictDecimals: true
});

With this configuration a ma and a point with behave like entering a letter(red exclamation flash).

Example

发布评论

评论列表(0)

  1. 暂无评论