#11889 closed defect (fixed)
NumberTextBox {places:'0,3'} does not format with maxPlaces onBlur
Reported by: | GreenGoblin | Owned by: | Douglas Hays |
---|---|---|---|
Priority: | high | Milestone: | 1.6 |
Component: | Dijit - Form | Version: | 1.5 |
Keywords: | NumberTextBox places blur | Cc: | Adam Peller |
Blocked By: | Blocking: |
Description
When specifying a range of decimal places for NumberTextBox? such as {places:'0,3'}, editing allows the correct range of decimal places but the field is not formatted with 3 decimal places when tabbing out of field.
As specified in the documentation:
To specify a field where 0 to 3 decimal places are allowed on input,
but after the field is blurred the value is displayed with 3 decimal places:
|{places:'0,3'}
A simple example:
<input dojoType="dijit.form.NumberTextBox?" id="testPlaces" name="testPlaces" constraints="{places:'0,3'}">
Attachments (2)
Change History (15)
comment:1 Changed 10 years ago by
Component: | General → Dijit |
---|---|
Owner: | changed from anonymous to Douglas Hays |
comment:2 Changed 10 years ago by
Cc: | Adam Peller added |
---|---|
Milestone: | tbd → 1.6 |
#10669 changed this behavior in dojo core
comment:3 Changed 10 years ago by
The issue is in dojo.number (dojo/number.js)
The comments indicate that a places range "n,m" will format to m places:
dojo.number.__FormatAbsoluteOptions // places: Number?|String? // number of decimal places. the range "n,m" will format to m places.
The relevant code is in dojo.number._formatAbsolute on lines 197-215
var valueParts = String(Math.abs(value)).split("."), fractional = valueParts[1] || ""; if(patternParts[1] || options.places){ if(comma){ options.places = options.places.substring(0, comma); } // Pad fractional with trailing zeros var pad = options.places !== undefined ? options.places : (patternParts[1] && patternParts[1].lastIndexOf("0") + 1); if(pad > fractional.length){ valueParts[1] = dojo.string.pad(fractional, pad, '0', true); } // Truncate fractional if(maxPlaces < fractional.length){ valueParts[1] = fractional.substr(0, maxPlaces); } }else{ if(valueParts[1]){ valueParts.pop(); } }
The calculation of maxPlaces is already done above this section so changing to the following seems appropriate and works properly in my testing:
var valueParts = String(Math.abs(value)).split("."), fractional = valueParts[1] || ""; if(maxPlaces){ // Pad fractional with trailing zeros if(maxPlaces > fractional.length){ valueParts[1] = dojo.string.pad(fractional, maxPlaces, '0', true); } // Truncate fractional if(maxPlaces < fractional.length){ valueParts[1] = fractional.substr(0, maxPlaces); } }else{ if(valueParts[1]){ valueParts.pop(); } }
Changed 10 years ago by
Attachment: | 11889.patch added |
---|
patch to trunk to make parse aware of editOptions
comment:4 Changed 10 years ago by
Please review the attached patch. In the referenced example, the NumberTextBox? widget instance now needs editOptions:{places:"0,3"} and constraints:{places:3} if you want the old behavior.
comment:5 Changed 10 years ago by
This looks like it should address the issue although I was a little surprised that you really did change the documentation. Does this mean you are going to change the documentation for dojo.number as well?
I would like to test and use these changes, so:
I am using the Google 1.5 CDN. Is there a CDN to access this trunk for testing? Is this change going to appear soon (1.5.1 instead of 1.6)? Is it possible for me to make a local change to NumberTextBox? or dojo.number and be able to integrate this with the CDN or is the only option to switch to full local source? I could not find a way using modulePaths to load dojo.number locally which would be useful until the change comes out.
Thank you
comment:6 Changed 10 years ago by
Resolution: | → fixed |
---|---|
Status: | new → closed |
(In [23070]) Fixes #11889. Make parse::NumberTextBox? and _setBlurValue::NumberTextBox? aware of editOptions that are in effect while the textbox has focus. Added additional automated tests (file renamed to robot/ValidationTextBox.html).
comment:7 Changed 10 years ago by
Should be able to continue using the 1.5 CDN and locally extend NumberTextBox? with just these changes.
comment:8 Changed 10 years ago by
Thank you, I did make a modified local version of NumberTextBox? with the changes and it works as specified. I was mainly having trouble trying to see if I could have a substitute dojo.number module while using a CDN. I could not come up with an easy answer but the final solution involved NumberTextBox? which was workable.
At this point, the dojo.number will need the documentation changed as well. Should I submit that as a new issue?
comment:10 Changed 10 years ago by
Resolution: | fixed |
---|---|
Status: | closed → reopened |
Starting with [23070] I'm getting 6 failures on ValidationTextBox?.html on chrome (windows and mac). It's passing on FF3.6/win. test_validate.html passes on [23069] on chrome.
comment:11 Changed 10 years ago by
Resolution: | → fixed |
---|---|
Status: | reopened → closed |
comment:12 Changed 10 years ago by
Component: | Dijit → Dijit - Form |
---|
Changed 8 years ago by
updated test case, type 1.3 in the first field and tab away, it will change to 1.300
Sounds like a bug, or at least we need an update to the doc...