Correct way to commit pending text field edits?
I have a window with a bunch of text fields. I also have an Apply button which takes the current settings and applies them to the data model. If I have edited text in a field but not hit return or tab or anything else that triggers target/action, the edit is ignored. So I need a way to commit any such pending edits as part of my response to the Apply button. It's not clear what the right way to do that is. I know about the Field Editor, but the various methods that pertain to it seem to be rather low level. I'd sort of expect to see some sort of validate and commit pending edits method at the window/window controller level that takes care of figuring out which control is focused, etc. Since there doesn't appear to be one, what should I use to write one? tia, cheers, Graham ___ 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 [EMAIL PROTECTED]
Re: Correct way to commit pending text field edits?
Hi Graham, Try -[NSControl validateEditing]. Validation sets the object value of the cell to the current contents of the cell's editor (the NSText object used for editing), storing it as a simple NSString or an attributed string object based on the attributes of the editor. -Ken On Thu, Jul 24, 2008 at 7:23 PM, Graham Cox [EMAIL PROTECTED] wrote: I have a window with a bunch of text fields. I also have an Apply button which takes the current settings and applies them to the data model. If I have edited text in a field but not hit return or tab or anything else that triggers target/action, the edit is ignored. So I need a way to commit any such pending edits as part of my response to the Apply button. It's not clear what the right way to do that is. I know about the Field Editor, but the various methods that pertain to it seem to be rather low level. I'd sort of expect to see some sort of validate and commit pending edits method at the window/window controller level that takes care of figuring out which control is focused, etc. Since there doesn't appear to be one, what should I use to write one? tia, cheers, Graham ___ 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/kenferry%40gmail.com This email sent to [EMAIL PROTECTED] ___ 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 [EMAIL PROTECTED]
Re: Correct way to commit pending text field edits?
I should mention I'm not using Core Data - by data model I mean my own d/m code. Mmmm, coffee... now there's a thought. Graham On 25 Jul 2008, at 12:30 pm, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: Apologies for the off-list reply, work email addy.. Try [managedObjectContext commitEditing] (from memory) - called just before the save. You can also reset the firstResponder, but that takes focus away and looks funny/not user friendly. Probably fine if you were raising an alert panel or some such. Hope that helps/is what you're after. I haven't had much coffee yet, it's a little early. :) -nick ___ 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 [EMAIL PROTECTED]
Re: Correct way to commit pending text field edits?
Graham Cox wrote: I need a way to commit ... pending edits as part of my response to the Apply button. I don't know that this is the correct way, but there is a built-in mechanism that will do what you want: If you were to makeFirstResponder nil for the window containing the text field, the textDidEndEditing method would be called on the active text field and then its data could be saved normally. You'd lose the edit state of course, but if you're applying changes I'm guessing that would be OK. HTH, Joel ___ 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 [EMAIL PROTECTED]
Re: Correct way to commit pending text field edits?
You need to call this on the NSTextField's cell: setSendsActionOnEndEditing:YES Hope it helps. -Chaitanya On 24-Jul-08, at 10:23 PM, Graham Cox wrote: I have a window with a bunch of text fields. I also have an Apply button which takes the current settings and applies them to the data model. If I have edited text in a field but not hit return or tab or anything else that triggers target/action, the edit is ignored. So I need a way to commit any such pending edits as part of my response to the Apply button. It's not clear what the right way to do that is. I know about the Field Editor, but the various methods that pertain to it seem to be rather low level. I'd sort of expect to see some sort of validate and commit pending edits method at the window/window controller level that takes care of figuring out which control is focused, etc. Since there doesn't appear to be one, what should I use to write one? tia, cheers, Graham ___ 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/chaitanya%40expersis.com This email sent to [EMAIL PROTECTED] ___ 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 [EMAIL PROTECTED]
Re: Correct way to commit pending text field edits?
On Jul 24, 2008, at 9:23 PM, Graham Cox wrote: I have a window with a bunch of text fields. I also have an Apply button which takes the current settings and applies them to the data model. If I have edited text in a field but not hit return or tab or anything else that triggers target/action, the edit is ignored. So I need a way to commit any such pending edits as part of my response to the Apply button. It's not clear what the right way to do that is. I know about the Field Editor, but the various methods that pertain to it seem to be rather low level. I'd sort of expect to see some sort of validate and commit pending edits method at the window/window controller level that takes care of figuring out which control is focused, etc. Since there doesn't appear to be one, what should I use to write one? You don't mention if you're using bindings. If you are, you should send one of the -commitEditing... messages to the NSController-derived mediating controllers. This is part of the NSEditor information protocol. Cheers, Ken ___ 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 [EMAIL PROTECTED]
Re: Correct way to commit pending text field edits?
chaitanya pandit wrote: You need to call this on the NSTextField's cell: setSendsActionOnEndEditing:YES sendsActionOnEndEditing appears to be ON by default. And it doesn't affect pending edits anyway. The problem is how to cause textDidEndEditing to fire. Hence my suggestion to makeFirstResponder nil for the window containing the text field. Although Ken Ferry's suggestion send one of the -commitEditing... messages to the NSController-derived mediating controllers. This is part of the NSEditor information protocol. seems more elegant than my suggestion to just slam the window's firstResponder. Sincerely, Joel ___ 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 [EMAIL PROTECTED]