Re: Bindings making NSNumberFormatter strange
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? H. 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 (Cocoa-dev@lists.apple.com) 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: Bindings making NSNumberFormatter strange
On Apr 23, 2009, at 2:25 PM, Lee Ann Rucker wrote: 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. There's no workaround. I tried writing my own Undo handler, but as you've discovered the changes happen before there's a chance to handle them. Formatters work, and bindings work, but the combination doesn't. The only solution I've found is to use a formatter without bindings, since having the formatter is more important than having bindings, useful as they may be. Just to be clear, are you saying that you can do field filtering with a formatter, with appropriate undo support, without bindings, or are you making a general remark about difficulties when using bindings with formatters? Thx, Keary Suska Esoteritech, Inc. Demystifying technology for your home or business ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
RE: Bindings making NSNumberFormatter strange
From: Keary Suska [cocoa-...@esoteritech.com] Sent: Thursday, April 23, 2009 2:04 PM To: Lee Ann Rucker Cc: Cocoa-Dev (Apple) Subject: Re: Bindings making NSNumberFormatter strange On Apr 23, 2009, at 2:25 PM, Lee Ann Rucker wrote: 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. There's no workaround. I tried writing my own Undo handler, but as you've discovered the changes happen before there's a chance to handle them. Formatters work, and bindings work, but the combination doesn't. The only solution I've found is to use a formatter without bindings, since having the formatter is more important than having bindings, useful as they may be. Just to be clear, are you saying that you can do field filtering with a formatter, with appropriate undo support, without bindings, or are you making a general remark about difficulties when using bindings with formatters? Two separate issues, both related to the fact that formatters that do filtering just aren't very robust. I never got undo to work with a formatter, with or without bindings; we ended up disabling it because it behaved so badly. For example, if you type two characters but one gets filtered out so there's only one left in the field, then try to undo, it tries to remove two characters and gives you a range error. It ought to be simple to fix, but too much of the action happens before developer code has a chance to intercept it. Bindings + formatters had the problem I mentioned farther down, but at least the users don't notice if you don't have bindings.___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Bindings making NSNumberFormatter strange
Hi, I have an (editable) NSTextField with an NSNumberFormatter attached to it. The text field is bound to some other numerical property (if you want to test this, you can just make a simple AppController and put the @property(readwrite) int foo; inside it, and bind the text field to AppController's foo). 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? 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. Thanks very much, U _ Show them the way! Add maps and directions to your party invites. http://www.microsoft.com/windows/windowslive/products/events.aspx___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
RE: Bindings making NSNumberFormatter strange
Noone has an idea? 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. 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. Thank you, U From: ulaibee...@hotmail.com To: cocoa-dev@lists.apple.com Date: Wed, 22 Apr 2009 15:26:51 + Subject: Bindings making NSNumberFormatter strange Hi, I have an (editable) NSTextField with an NSNumberFormatter attached to it. The text field is bound to some other numerical property (if you want to test this, you can just make a simple AppController and put the @property(readwrite) int foo; inside it, and bind the text field to AppController's foo). 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? 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. Thanks very much, U . _ More than messages–check out the rest of the Windows Live™. http://www.microsoft.com/windows/windowslive/___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: Bindings making NSNumberFormatter strange
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 ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
RE: Bindings making NSNumberFormatter strange
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? H. 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: cocoa-dev@lists.apple.com From: cocoa-...@esoteritech.com To: ulaibee...@hotmail.com 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=createwx_url=/friends.aspxmkt=en-us___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: Bindings making NSNumberFormatter strange
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)? 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? H.control:didFailToFormatString:errorDescription: Using control:didFailToFormatString:errorDescription: and always returning YES will stop the Formatting Error sheet. A custom NSNumberFormatter subclass can be used to block characters that are not in decimalDigitCharacterSet and sound a beep. Read the last paragraph of: http://developer.apple.com/documentation/Cocoa/Conceptual/DataFormatting/Articles/CreatingACustomFormatter.html --Nathan ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com