Re: Radio button group and binding "enabled" of other GUI elements
Re: Radio button group and binding "enabled" of other GUI elements
- Subject: Re: Radio button group and binding "enabled" of other GUI elements
- From: Ricky Sharp <email@hidden>
- Date: Fri, 23 Sep 2005 08:25:38 -0500
On Sep 23, 2005, at 4:13 AM, Kaspar Fischer wrote:
Hi all,
Given a group of 3 radio buttons and, in addition, three
text fields, what is the best way to enable text field 1
if and only if radio button 1 is selected (and the same
for the other fields)?
More precisely: I have there radio buttons
o A
o B
o C
and three text fields (just to illustrate the problem),
and I want that the text field corresponding to A is
enabled iff radio button A is selected and that the
text field for B is enabled iff B is selected and so on.
With only *two* buttons and text fields I would simply
use a NSObjectController with a key "isASelected" and
then bind the selectedIndex of the radio button's NSMatrix
to this "isASelected"; I can then bind the enabled of
text field A to "isASelected" and the enabled of text field
B to "isASelected" with value transformer NSNegateBoolean.
Any suggestions to achieve the same for more than two
buttons and text fields?
Thanks,
Kaspar
P.S. One way I see (which is not so elegant as it needs
coding) is to write value transformers "Is0", "Is1",
and "Is2" which return true if and only if the number
is 0 (or 1, or 2 respectively). I could then again use
an NSObjectController with a key "selectedIndex" and
bind the enabled of the text fields using the Is0/1/2
value transformers.
Using value transformers is a valid approach.
You could also set up dependent keys. In your controller, create an
accessor for radioIndex and bind the selected index of your radio
group to that. Then create three getters: isASelected through
isCSelected and bind the enabled state of your text fields to that.
Their implementation would be like:
-(BOOL)isASelected
{
return [[self radioIndex] == 0];
}
Finally, in your controller's +initialize, set up dependent keys so
that when radioIndex changes, your three "isSelected" attributes will
be changed accordingly.
Finally, something else to consider is to just hide your text fields
when not in use. You could then use a borderless, tabless,
transparent tabview (3 tabs; one for each text field). Then simply
bind the radio group's selected index to the tab view's tab index.
___________________________________________________________
Ricky A. Sharp mailto:email@hidden
Instant Interactive(tm) http://www.instantinteractive.com
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden