Opened 7 years ago

Last modified 4 years ago

#18562 new defect

[partial patch][cla] NumberTextBox rounds even with constraints: {round: -1}

Reported by: Michael Schall Owned by:
Priority: undecided Milestone: 1.14
Component: Dijit - Form Version: 1.10.4
Keywords: Cc:
Blocked By: Blocking:


The NumberTextBox? rounds input on blur even if constraints is set to not round. An example showing constraints with and without rounding is available on jsFiddle.

With the following code, typing in 1.105 will round to 1.11 (IE) and 1.10 (Chrome, Firefox). The different result is due to JavaScript? number handling. However, I'm explicitly asking it to NOT round.

    <legend>constraints:{constraints:{pattern:'##0.00', round:-1}}</legend>
    <input type="text" data-dojo-type="dijit/form/NumberTextBox" data-dojo-props="constraints:{pattern:'##0.00', round:-1}" value="0" />
        <li>good: 1.1 is formatted to 1.10 on blur</li>
        <li>bad: 1.105 is rounded to 1.11 on blur (IE11)</li>
        <li>bad: 1.105 is truncated to 1.10 on blur (Chrome,Firefox)</li>

A potential fix for this is to check before rounding in NumberTextBox?'s filter function:

  • NumberTextBox.js

    196196                        //              See `dijit/form/TextBox.filter()` for more details.
    197197                        if(value == null  /* or undefined */ || typeof value == "string" && value ==''){
    198198                                return NaN;
    199                         }else if(typeof value == "number" && !isNaN(value) && value != 0){
     199                        }else if(typeof value == "number" && !isNaN(value) && value != 0 && this.constraints.round !== -1){
    200200                                value = number.round(value, this._decimalInfo.places);
    201201                        }
    202202                        return this.inherited(arguments, [value]);

This does have a couple validation display issues:

  1. A validation is added, but no validation text shows.
  2. The validation is removed on focus, so the user doesn't really have a chance to know what is wrong.

I have not been able to resolve the validation message issues at this time.

Change History (4)

comment:1 Changed 6 years ago by dylan

Milestone: tbd1.12

comment:2 Changed 6 years ago by dylan

Summary: NumberTextBox rounds even with constraints: {round: -1}[partial patch][cla] NumberTextBox rounds even with constraints: {round: -1}

comment:3 Changed 6 years ago by Adrian Vasiliu

Given round is deprecated, and something like places:'0,4' should work for specifying the min-max number of decimals. Not sure if this issue is a bug, or invalid, though.

comment:4 Changed 4 years ago by dylan

Milestone: 1.131.14
Note: See TracTickets for help on using tickets.