NumberTextBox constraint places/rounding/formatting

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

NumberTextBox constraint places/rounding/formatting

Michael Schall
I'm having issues getting constraints for the NumberTextBox working as I want them to.

The specific issue I'm having is how to setup the text box to format 1.2 to 1.20 when it looses focus, without rounding 1.205 to 1.21 or truncating 1.205 to 1.20.  I want the user to fix the extra digit(s) after the decimal.  

Here is a jsfiddle showing what I have tried.

I get the formatting I want with pattern:'##0.00', but then it rounds 1.205 to 1.21.  I can fix the rounding by adding round:-1, but then it truncates 1.205 to 1.20.

I can get "no rounding/truncating" functionality with places: 2, but then it doesn't format 1.2 to 1.20.  

Both pattern and places can't coexist as places overrides pattern.

Thanks for your help.
Reply | Threaded
Open this post in threaded view
|

Re: NumberTextBox constraint places/rounding/formatting

Michael Schall
The round attribute of the constraint seems to behave differently between IE (11) and Chrome/Firefox.

IE seems to always round the value even if I specify round:-1.  Chrome/Firefox always truncates the value even with the default value of round:0.

I have updated my jsFiddle with my findings.  Can anyone confirm?
Reply | Threaded
Open this post in threaded view
|

Re: NumberTextBox constraint places/rounding/formatting

Karl Tiedt
I suspect your problem is directly related to the notes here:


-Karl Tiedt

On Tue, Mar 17, 2015 at 2:50 PM, Michael Schall <[hidden email]> wrote:
The round attribute of the constraint seems to behave differently between IE
(11) and Chrome/Firefox.

IE seems to always round the value even if I specify round:-1.
Chrome/Firefox always truncates the value even with the default value of
round:0.

I have updated my  jsFiddle <http://jsfiddle.net/dnnp77hy/>   with my
findings.  Can anyone confirm?



--
View this message in context: http://dojo-toolkit.33424.n3.nabble.com/NumberTextBox-constraint-places-rounding-formatting-tp4005588p4005632.html
Sent from the Dojo Toolkit mailing list archive at Nabble.com.
--
Dojo Toolkit: http://dojotoolkit.org/
Tutorials: http://dojotoolkit.org/documentation/

[hidden email]
To unsubscribe, visit: http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest


--
Dojo Toolkit: http://dojotoolkit.org/
Tutorials: http://dojotoolkit.org/documentation/

[hidden email]
To unsubscribe, visit: http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest
Reply | Threaded
Open this post in threaded view
|

Re: NumberTextBox constraint places/rounding/formatting

Michael Schall
Karl - Thanks for your reply...  I thought the format was somehow doing this, but would agree with you it is rounding issue. I have updated the jsfiddle with a rounding section...

number.round(1.105, 2) = 1.1 (Chrome)

However, I don't want to round at all...  My requirement for this project is that there is no rounding/truncating.  The user must fix the validation issue.  The places: 2 is very close to what I need.  It has a great feature where it adds validation as you type if you go past 2 places past the decimal.  The formatting of number 2.3 just needs to add the 0 in 2.30 before attempting the validation on blur (like it does this if only the pattern ##0.00 is specified).

Thanks again for your response.

On Tue, Mar 17, 2015 at 8:14 PM, Karl Tiedt [via Dojo Toolkit] <[hidden email]> wrote:
I suspect your problem is directly related to the notes here:


-Karl Tiedt

On Tue, Mar 17, 2015 at 2:50 PM, Michael Schall <[hidden email]> wrote:
The round attribute of the constraint seems to behave differently between IE
(11) and Chrome/Firefox.

IE seems to always round the value even if I specify round:-1.
Chrome/Firefox always truncates the value even with the default value of
round:0.

I have updated my  jsFiddle <http://jsfiddle.net/dnnp77hy/>   with my
findings.  Can anyone confirm?



--
View this message in context: http://dojo-toolkit.33424.n3.nabble.com/NumberTextBox-constraint-places-rounding-formatting-tp4005588p4005632.html
Sent from the Dojo Toolkit mailing list archive at Nabble.com.
--
Dojo Toolkit: http://dojotoolkit.org/
Tutorials: http://dojotoolkit.org/documentation/

[hidden email]
To unsubscribe, visit: http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest


--
Dojo Toolkit: http://dojotoolkit.org/
Tutorials: http://dojotoolkit.org/documentation/

[hidden email]
To unsubscribe, visit: http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest



If you reply to this email, your message will be added to the discussion below:
http://dojo-toolkit.33424.n3.nabble.com/NumberTextBox-constraint-places-rounding-formatting-tp4005588p4005644.html
To unsubscribe from NumberTextBox constraint places/rounding/formatting, click here.
NAML

Reply | Threaded
Open this post in threaded view
|

Re: NumberTextBox constraint places/rounding/formatting

Michael Schall
I finally got back to this...  I think I have found an issue in the NumberTextBox when attempting to turn off rounding.

If I define a NumberTextBox like the following:

<input type="text" data-dojo-type="dijit/form/NumberTextBox" data-dojo-props="constraints:{pattern:'##0.00', round:-1}" value="0" />

The text box will still round to 2 decimal places.  I have found this in the NumberTextBox's filter function:

        }else if(typeof value == "number" && !isNaN(value) && value != 0){
                value = number.round(value, this._decimalInfo.places);
        }

If I check the constraint before calling round, that can be avoided:

        }else if(typeof value == "number" && !isNaN(value) && value != 0 && this.constraints.round !== -1){
                value = number.round(value, this._decimalInfo.places);
        }

This however introduces an issue where the validator is not showing a tooltip with the reason.
Reply | Threaded
Open this post in threaded view
|

Re: NumberTextBox constraint places/rounding/formatting

Michael Schall
I created two tickets for this issue.  

The one I'm actually interested in:
NumberTextBox doesn't fill trailing zeros when using constraints: {places: 2} https://bugs.dojotoolkit.org/ticket/18563

An issue, but I'll use the places option
NumberTextBox rounds even with constraints: {round: -1} https://bugs.dojotoolkit.org/ticket/18562

Thanks for your help.

On Fri, Apr 10, 2015 at 1:53 PM, Michael Schall <[hidden email]> wrote:
I finally got back to this...  I think I have found an issue in the
NumberTextBox when attempting to turn off rounding.

If I define a NumberTextBox like the following:

<input type="text" data-dojo-type="dijit/form/NumberTextBox"
data-dojo-props="constraints:{pattern:'##0.00', round:-1}" value="0" />

The text box will still round to 2 decimal places.  I have found this in the
NumberTextBox's filter function:

        }else if(typeof value == "number" && !isNaN(value) && value != 0){
                value = number.round(value, this._decimalInfo.places);
        }

If I check the constraint before calling round, that can be avoided:

        }else if(typeof value == "number" && !isNaN(value) && value != 0 *&&
this.constraints.round !== -1*){
                value = number.round(value, this._decimalInfo.places);
        }

This however introduces an issue where the validator is not showing a
tooltip with the reason.




--
View this message in context: http://dojo-toolkit.33424.n3.nabble.com/NumberTextBox-constraint-places-rounding-formatting-tp4005588p4005880.html
Sent from the Dojo Toolkit mailing list archive at Nabble.com.
--
Dojo Toolkit: http://dojotoolkit.org/
Tutorials: http://dojotoolkit.org/documentation/

[hidden email]


--
Dojo Toolkit: http://dojotoolkit.org/
Tutorials: http://dojotoolkit.org/documentation/

[hidden email]
To unsubscribe, visit: http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest