How to correct the operation of the up/down arrows when entering a number with 2 decimal places.

How to correct the operation of the up/down arrows when entering a number with 2 decimal places.

ingezoneingezone Posts: 20Questions: 8Answers: 0

Link to test case: http://live.datatables.net/gasituho/1/edit
Debugger code (debug.datatables.net):
Error messages shown:
Description of problem:

Problem 1:
When using the up/down arrows with increment of "1.00", it does not put the decimal place "x,00". How can I add the leading zeros during each increment. Example:
0.00
1.00
2.00
3.00

Problem 2:
When I use the property
attr: {
type: "number",
}
By entering the digits manually without using the up/down arrow, it also allows you to enter text manually.

As I block the text entry and only allow numbers from 0-9.

Answers

  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin

    it does not put the decimal place "x,00". How can I add the leading zeros during each increment

    Reading the HTML specification I don't think it is possible with just attributes. You'd need to use a little Javascript such as:

      editor.field('tnumber').input().on('change', function () {
        var val = parseFloat(this.value);
        this.value = val.toFixed(2);
      });
    

    http://live.datatables.net/yojipoju/1/edit

    By entering the digits manually without using the up/down arrow, it also allows you to enter text manually.

    Use a keypress event listener to disallow non-numeric (or decimal place) input.

    Regards,
    Allan

Sign In or Register to comment.