|
> In a dialog the user should input float numbers. How to allow only
> digits, $. and $, characters to type into a TextEdit.
[]
> What I want.
> Is there any possibility to use a trigger event instead.
I don't think so, at least not in the way I think you mean.
One solution might be the MaskedEdit class. This relies on a commercial COM
component being available though and, as my system is not allowed to use it,
I can't tell you a lot more.
Another solution would be to use a new Presenter in place of
NumberPresenter. For example -
TextPresenter subclass: #MyNumberPresenter
MyNumberPresenter>>onViewOpened
super onViewOpened.
self view updatePerChar: true
MyNumberPresenter>>onValueChanged
| bad caretPos |
caretPos := self view caretPosition.
bad := self model value reject: [:each | '0123456789.,' includes: each].
bad isEmpty ifTrue: [^self].
Sound bell.
self model value: (self model value copyWithoutAll: bad).
self model value size + 2 = caretPos
ifTrue: [self view caretPosition: caretPos]
ifFalse: [self view caretPosition: caretPos - 1]
The main difference is that the Model for this Presenter is a String so you
will have to do the conversions yourself. This might be an advantage as you
can then control whether a , is used. As a demo
s := MyNumberPresenter showOn: '123,456,789.098'
opens a demo Shell with the above number visible. Edit the text, it now
only allows digits $. and $, and then close the Shell. Evaluating
Number fromString: (s value copyWithout: $,)
should answer the new Number
Regards
Ian
|