Opened 9 years ago

Closed 9 years ago

#10669 closed defect (fixed)

currencyTextBox: places constraint fails

Reported by: Jean-Rubin Leonard Owned by: Adam Peller
Priority: high Milestone: 1.5
Component: Core Version: 1.4.0
Keywords: currencyTextBox numberTextBox rounding places decimals places Cc:
Blocked By: Blocking:

Description

Hi, in currencyTextBox (hereafter cTB), we are supposed to do constraints="{places:'3,6'}" and be able to enter a number with between 3 to 6 decimals like 1.234 or 1.2345 or 1.234567. That functionality does not work however as is shown in the attached test case. What happens is that upon entering something like 1.123456, on blur the cTB's content reverts to 1.12. It's therefore truncated to 2 dijits. if one enter 1.135689, there will be a truncation but also some upward rounding and the cTB will be set at 1.14. It seems that the cTB's precision is hard-coded at 2 decimals. Thanks for looking into it, JR

Attachments (1)

testPlaces.html (1.3 KB) - added by Jean-Rubin Leonard 9 years ago.

Download all attachments as: .zip

Change History (5)

Changed 9 years ago by Jean-Rubin Leonard

Attachment: testPlaces.html added

comment:1 Changed 9 years ago by bill

Owner: set to Douglas Hays

comment:2 Changed 9 years ago by Douglas Hays

Component: DijitCore
Owner: changed from Douglas Hays to Adam Peller

The problem is in dojo.number._formatAbsolute

var maxPlaces = (options.places >= 0) ? options.places : (patternParts[1] && patternParts[1].length) || 0;
if(!(options.round < 0)){
        value = dojo.number.round(value, maxPlaces, options.round);
}
...
if(options.places){
        var comma = dojo.isString(options.places) && options.places.indexOf(",");
        if(comma){
                options.places = options.places.substring(comma+1);
        }

Note that maxPlaces is initialized assuming that options.places is a singular integer, but then just a few lines down, the true maxPlaces is carved out of the #,# construct for places. The code should be rearranged slightly and this problem will be fixed.
A workaround hack would be to set the constraints property {round:0.0005}

comment:3 Changed 9 years ago by Adam Peller

Milestone: tbd1.5

patches/fixes are always welcome. I will try to address this for 1.5

comment:4 Changed 9 years ago by Adam Peller

Resolution: fixed
Status: newclosed

(In [21867]) Fixes #10669 - formatting a number with constraints.places indicating a range

Note: See TracTickets for help on using tickets.