Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Disabling a Button based on Text Field content



On Thursday, July 31, 2003, at 03:21 PM, Tom Burns wrote:

I'm new to the list, but searched the archives and couldn't find the answer I needed. I need a way to disable a button if a certain text field is empty, then re-enable it once the user inputs a string.

Try setting the text field's delegate to some object that can control the button, and then do something like this, where "theTextField" is the NSTextField in question and "button" is the NSButton...

(Warning: Written in Mail, not tested, use at your own risk, etc.)

- (void)textDidEndEditing:(NSNotification *)notification
{
if ([notification object] == theTextField)
{
if ([[textField stringValue] isEqualToString:@""])
{
[button setEnabled:NO];
}
else
{
[button setEnabled:YES];
}
}
}

If you need this to run when the text is simply changed, rather than when the editing is finished, then change the above method to "textDidChange:" instead.

Nick Zitzmann
AIM/iChat: dragonsdontsleep
Check out my software page: http://seiryu.home.comcast.net/

"I have always wished that my computer would be as easy to use as my telephone. My wish has come true. I no longer know how to use my telephone." - Bjarne Stroustrup
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.
References: 
 >Disabling a Button based on Text Field content (From: Tom Burns <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.