Re: Bindings making NSNumberFormatter strange
Re: Bindings making NSNumberFormatter strange
- Subject: Re: Bindings making NSNumberFormatter strange
- From: Keary Suska <email@hidden>
- Date: Thu, 23 Apr 2009 09:20:51 -0600
On Apr 22, 2009, at 6:24 PM, Ulai Beekam wrote:
So I really must make a custom field editor to accomplish on-the-fly
validation (i.e. disallowing on-the-fly invalid characters)?
It is not your only choice, but it is probably the best choice.
Another poster suggested using isPartialStrignValid of the formatter,
but I have tried this in the past and run into undo issues,
particularly when using it to "filter" input. The problem is that undo
registration happens before the validation call, and somehow the "undo
typing" feature remembers the string, so when you change the string in
the validator method, and then undo, you can get add results and out-
of-bounds exceptions. Since then I haven't looked into why this
happens and how to get around it, if at all possible.
I suppose I could do a custom field editor and override keyDown:,
checking for characters in [NSCharacterSet
decimalDigitCharacterSet], etc. In fact, having made some custom
field editors in the past I know I would be able to do this.
However, I consider this to be a somewhat lame hack :( I therefore
want to make sure with you guys that there is no easier solution to
this, e.g. to somehow use the number formatter as a basis for
automatic on-the-fly validation.
I think that is exactly what you want to do, and doesn't sound like a
lame hack to me. But someone else may have better advice.
There is a solution that seems to me a bit of a hack, but works in a
pinch: implement the -controlTextDidChange: delegate method, and in
that method check for invalid characters, and if found, beep, clean
them out, then set the fields value to the cleaned string.
The whole thing just seems strange to me. Because when the text
field is not bound, on-the-fly validation seems to work just fine!
But this great feature goes away as soon as the text field is bound.
That is, as soon as the text field is bound, the validation stops
being on-the-fly and goes elsewhere instead. Is there no way having
the validation ALSO as an on-the-fly thing? Hmmmm.
I am not sure what you are describing here. Did you check
"continuously updates value" in the binding?
Best,
Keary Suska
Esoteritech, Inc.
"Demystifying technology for your home or business"
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden