• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Disabling a Button based on Text Field content
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Disabling a Button based on Text Field content


  • Subject: Re: Disabling a Button based on Text Field content
  • From: Nick Zitzmann <email@hidden>
  • Date: Thu, 31 Jul 2003 16:13:37 -0700

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>)

  • Prev by Date: Re: Linking a Menu To A Document
  • Next by Date: How do I display a Window from a bundle?
  • Previous by thread: Disabling a Button based on Text Field content
  • Next by thread: Re: Memory Management (Part I)
  • Index(es):
    • Date
    • Thread