RE: Bindings making NSNumberFormatter strange
RE: Bindings making NSNumberFormatter strange
- Subject: RE: Bindings making NSNumberFormatter strange
- From: Ulai Beekam <email@hidden>
- Date: Thu, 23 Apr 2009 00:24:49 +0000
- Importance: Normal
So I really must make a custom field editor to accomplish on-the-fly validation (i.e. disallowing on-the-fly invalid characters)?
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.
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'm hoping for some more elaboration on this to gain a bit more understanding. But so far, thanks very much for your reply Keary. Much appreciated!
----------------------------------------
> CC: email@hidden
> From: email@hidden
> To: email@hidden
> Subject: Re: Bindings making NSNumberFormatter strange
> Date: Wed, 22 Apr 2009 16:46:12 -0600
>
> On Apr 22, 2009, at 3:57 PM, Ulai Beekam wrote:
>
>> To elaborate, when not using bindings, the default behavior of text
>> fields with a number formatter is that when a user tries to enter
>> "abc" in it, the text field refuses to lose focus and makes a
>> beeping sounds.
>>
>> However, when the text field's value binding has been set, a sheet
>> is shown, which I think is a bad user experience.
>
> That's because no one is handling the error. Bindings gives you some
> automatic error support. Otherwise you have to handle the error
> yourself. This is well documented. If you don't like the experience,
> then change it.
>
>> In fact it would be even better to just disallow entering of invalid
>> characters in the first place. But such a method would have to work
>> even if the text field's value binding is set.
>
> I agree with you that having some sort of built-in support for entry
> filters would be great (I would add length limiters as well). I think
> we had this back in the Mac toolbox days, if I am remembering properly.
>
> Anyway, there are two different issue to consider. One is validation,
> and the other is custom editor behavior. They are really two different
> problems, although there is overlap.
>
>>> My problem is that when I type some invalid stuff in the text
>>> field, such as some letters "abc", I don't get a beep (which is the
>>> normal behaviour and the one I want), but I get some sheet popping
>>> up saying "Formatting Error". I don't want this sheet. I want the
>>> beep like usual. How can I get rid of this sheet behaviour that the
>>> bindings is causing? And why is it even causing it?
>>>
>
> Because that's how formatters work. Getting rid of the sheet is
> nontrivial if you allow the formatter or bindings to do validation.
> Also, your formatter (or your model object, using key-value
> validation) can provide a more sensible error message if you choose.
>
>>> Second question: How can I make my text field just disallow
>>> entering of invalid characters in the first place (and producing
>>> beep when it is tried)? I want, as you probably guessed, a method
>>> that is compatible with bindings.
>
>
> You can use the formatter to check data on the fly, but you have to
> control the undo manager or you will get exceptions on undo. You can
> also have a custom field editor, for finer grained control. Both of
> these have decent documentation. I would be surprised if no-one has a
> framework that offers some of this behavior.
>
> HTH,
>
> Keary Suska
> Esoteritech, Inc.
> "Demystifying technology for your home or business"
>
_________________________________________________________________
Invite your mail contacts to join your friends list with Windows Live Spaces. It's easy!
http://spaces.live.com/spacesapi.aspx?wx_action=create&wx_url=/friends.aspx&mkt=en-us_______________________________________________
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