I would like to have a NumberSpinner and/or NumberTextBox be able to do two things:
- Display a value with a precision of 1 decimal place.
- Round those values to the .5
I would also like it if the rounding occured while typing or at the minimum when the textbox loses focus. If I attempt to type 5.2
it will round to 5.0
. If I type 6.345
it will round to 6.5
.
I've attempted a wild mixture of values using places
, pattern
and round
properties on both the constraints
and/or editOptions
objects. Nothing works.
Notes:
- As for a NumberSpinner I set
smallDelta
to0.5
and it will increment property when using the spinner arrows. - From what I understand the
places
property will override anypattern
property you've set. - I have yet to get rounding to work.
- According to the source documentation for
dojo/number
I should be able to use a pattern based on these guidelines to round with. I've tried various versions of#.50##
with no success. It seems to add50
to the inputed value with no rounding. Maybe I'm not getting it? - I see the default
editOptions
pattern
value is#.#####
but when the textbox loses focus it rounds to three decimal places. So something else is overriding that pattern? - Digging through some of the Dijit code it looks like the
round()
method ofdojo/number
is not being passed the anincrement
parameter inNumberTextBox.js
in thefilter()
method. So settinground
as a property of one of the two config objects above does nothing at all?
Here is a basic jsFiddle using NumberSpinner that attempts some rounding and decimal precision.
One of my attempts:
<input
id="test"
type="text"
data-dojo-type="dijit/form/NumberSpinner"
data-dojo-props="
value: 5,
smallDelta: 0.5,
constraints: { min: 5, max: 1000, places: 1, round: 5 },
editOptions: {
places: 1
}
">
I'm sure I can get by with extending a method on NumberTextBox
or NumberSpinner
like filter()
via a custom mixin but would prefere to do it through config options on data-dojo-props
if at all possible.
Like with a lot of Dojo somethings aren't as apparent or easy as they seem they would be, especially with Dijits. An there's just not a lot of info out there on some of the Dijits and the documentation loves to gloss over things and has always been a huge weak point of dojo.
Can anyone help clarify any of this for me. I feel like I am close and need someone to point out what I'm mostlikely overlooking. I would simply like to round a value to the nearest .5 and/or display a single decimal place that is rounded.