Opened 5 years ago

Closed 5 years ago

Last modified 5 years ago

#18260 closed defect (fixed)

NumberTextBox is rounding values

Reported by: bwa Owned by: Bill Keese <bill@…>
Priority: high Milestone: 1.10.1
Component: Dijit - Form Version: 1.10.0
Keywords: Cc: cjolif, Terence Kent
Blocked By: Blocking:

Description (last modified by bill)

When migrating form dojo 1.8 to dojo 1.10 our NumberTextBox? is starting to round values.

Our constraints is set as following:

    data-dojo-props="constraints:
    {
	min: 0,
        max: 133,
        pattern: '##0.##'
    },

With dojo 1.8 and 1.9 I can enter a values of 5,88 and have it accepted. When changing to dojo 1.10, the input of 5,88 is rounded up to 6 when focus is lost.

Here's a complete example :

<!DOCTYPE html>
<html>
<head>
    <title>Demo page</title>
    <style type="text/css">
        @import "http://ajax.googleapis.com/ajax/libs/dojo/1.10.0/dijit/themes/tundra/tundra.css";
        @import "http://ajax.googleapis.com/ajax/libs/dojo/1.10.0/dojo/resources/dojo.css";
    </style>
    <script data-dojo-config="async:true, parseOnLoad: true"
            src="http://ajax.googleapis.com/ajax/libs/dojo/1.10.0/dojo/dojo.js.uncompressed.js" >
    </script>
	<script>
		require(["dojo/parser", "dijit/form/NumberTextBox"]);
	</script>    
</head>

<body class="tundra">
<label for="textbox">Integer between 0 and 133:</label>
<input id="textbox" type="text"
    data-dojo-type="dijit/form/NumberTextBox"
    name= "elevation"
    required="true"
    value="0"
    data-dojo-props="constraints:
    {
		min: 0,
        max: 133,
        pattern: '##0.##'
    },
    invalidMessage:'Please enter a numeric value.',
    rangeMessage:'Invalid elevation.'" />

<button>dummy button (tab to here)</button>
</body>
</html>

Change History (14)

comment:1 Changed 5 years ago by cjolif

Cc: cjolif added

comment:2 Changed 5 years ago by bwa

This is very urgent for our company. We have decided to migrate from 1.8 til 1.10, and most works fine, but this is not, and causing a big trouble for us, and the input is altered to something wrong. We require 2 digits in our input fields, but now it's rouded up/down to nearest integer.

Last edited 5 years ago by bwa (previous) (diff)

comment:3 Changed 5 years ago by bwa

I think the bug is in NumberTextBox? when this was introduced ( sometimes after 1.9.0) :

	// A private helper function to determine decimal information
	// Returns an object with "sep" and "places" properties
	var getDecimalInfo = function(constraints){
         ...
         ...




		_setConstraintsAttr: function(/*Object*/ constraints){
			...
                        ...

   ----- here ---->>>>    // this resolves to 0 with a pattern of pattern: '##0.##'
			this._decimalInfo = getDecimalInfo(constraints);
		},

then it's rounded by this._decimalInfo.places which is now 0, it should be 2 ?

		filter: function(/*Number*/ value){
			// summary:
			//		This is called with both the display value (string), and the actual value (a number).
			//		When called with the actual value it does corrections so that '' etc. are represented as NaN.
			//		Otherwise it dispatches to the superclass's filter() method.
			//
			//		See `dijit/form/TextBox.filter()` for more details.
			if(value == null  /* or undefined */ || typeof value == "string" && value ==''){
				return NaN;
			}else if(typeof value == "number" && !isNaN(value) && value != 0){
				value = number.round(value, this._decimalInfo.places);
			}
			return this.inherited(arguments, [value]);
		},
Last edited 5 years ago by bill (previous) (diff)

comment:4 Changed 5 years ago by bill

Cc: Terence Kent added

Hi Terence, the code he's mentioning is from you, for #17955, can you work on this ticket? (I haven't analyzed it in detail, so it's possible it's a user error, but it sounds like a regression.)

comment:5 Changed 5 years ago by bill

Description: modified (diff)

comment:6 Changed 5 years ago by bwa

More investigating shows that bundle.decimal is ',' for no-nb (norway), and it looks like the next line of code is using ',' for splitting the pattern, but the decimal split character is '.'

see http://www.unicode.org/reports/tr35/tr35-numbers.html#Special_Pattern_Characters

places = placesSpecified ? constraints.places : (pattern.indexOf(bundle.decimal) != -1 ? pattern.split(bundle.decimal)[1].replace(/[#0]/g, "").length : 0);

If I change bundle.decimal to '.', the function works.

Then the problem migth be a mixup between bundle.decimal and the unicode pattern decimal character

Last edited 5 years ago by bwa (previous) (diff)

comment:7 Changed 5 years ago by cjolif

Milestone: tbd1.10.1
Priority: undecidedhigh

comment:8 Changed 5 years ago by cjolif

Yes the problem is clearly in the new code in getDecimalInfo where it seems the pattern code is trying to leverage bundle.decimal where it should not as the pattern format is independent of the locale.

comment:9 Changed 5 years ago by Terence Kent

@bwa

Thanks for the investigation, that's certainly the issue

@bill

I'll get a patch and jsfiddle in for this shortly

comment:10 Changed 5 years ago by Terence Kent

@bwa

I'm running the regression tests with the patch now, can you confirm that the drop-in patch in this jsfiddle works for you?

comment:11 Changed 5 years ago by bwa

@tkent Yes, the jsfiddle looks to be the right solution and worked as expected. It also did round when 3 decimals was entered.

So it looks like we have nailed it.

Thanks.

comment:12 Changed 5 years ago by cjolif

We are building 1.10.1 tomorrow, would be good to have the fix in before then.

Last edited 5 years ago by cjolif (previous) (diff)

comment:14 Changed 5 years ago by Bill Keese <bill@…>

In 00568aa6e4f319e1440918e6bd79e36bbbc7046e/dijit:

Error: Processor CommitTicketReference failed
Unsupported version control system "git": Can't find an appropriate component, maybe the corresponding plugin was not enabled? 

comment:13 Changed 5 years ago by Bill Keese <bill@…>

Owner: set to Bill Keese <bill@…>
Resolution: fixed
Status: newclosed

In eb4d66a779f5a044c011c7f24d6f4641ba00ef74/dijit:

Error: Processor CommitTicketReference failed
Unsupported version control system "git": Can't find an appropriate component, maybe the corresponding plugin was not enabled? 
Note: See TracTickets for help on using tickets.