client/js/controls/numerictextcontrol/numerictextcontrol.coffee in rsence-pre-3.0.0.10 vs client/js/controls/numerictextcontrol/numerictextcontrol.coffee in rsence-pre-3.0.0.11
- old
+ new
@@ -33,11 +33,13 @@
if _delta < 0
_value = _value-@options.numberIncrement
else
_value = _value+@options.numberIncrement
_value = @validateNumber(_value)
- @setValue( _value )
+ @setValue(_value) if @_isValid
+ @setTextFieldValue( _value, true )
+ true
keyDown: (_key)->
if _key == Event.KEY_UP
@mouseWheel(1)
return true
@@ -46,20 +48,21 @@
return true
false
_numbers: ['0','1','2','3','4','5','6','7','8','9']
validateNumber: (_value)->
+ if isNaN( _value )
+ _value = @value
+ console.log('isNaN')
+ @setValid(false)
if @options.decimalNumber
_value = parseFloat(_value)
if @options.decimalPlaces != null
_decPlaces = Math.pow(10,@options.decimalPlaces)
_value = Math.round(_value*_decPlaces)/_decPlaces
else
_value = parseInt( _value, 10 )
- if isNaN( _value )
- _value = @value
- @setValid(false)
if _value > @maxValue
_value = @maxValue
@setValid(false)
else if _value < @minValue
@setValid(false)
@@ -80,16 +83,12 @@
_value += _chr
@validateNumber( _value )
valueToField: (_value)->
_value = @validateNumber(_value)
if @options.decimalNumber and @options.decimalPlaces != null
- if _value - Math.round(_value) == 0
- _value = _value+@options.decimalSeparator
- for n in [0...@options.decimalPlaces]
- _value += '0'
- else
- _value = _value.toString().replace('.',@options.decimalSeparator)
+ _value = _value.toFixed(@options.decimalPlaces)
+ _value = _value.replace('.',@options.decimalSeparator)
_value
refreshValue: ->
@base()
@stepper.setValue(@value) if @stepper?
@@ -99,10 +98,10 @@
## input is a number.
###
# validateText: (_value)-> _value
drawSubviews: ->
- @setStyleOfPart('value','textAlign','right')
+ @setStyleOfPart('value','textAlign','right') unless @options.style? and @options.style.textAlign
if @options.withStepper
this._extraLabelRight += 14
@setStyleOfPart('label','right',this._extraLabelRight+'px')
_top = Math.round((@rect.height-22)/2)
@stepper = HStepper.extend(