2 Copyright (C) 2000-2005 SKYRIX Software AG
4 This file is part of SOPE.
6 SOPE is free software; you can redistribute it and/or modify it under
7 the terms of the GNU Lesser General Public License as published by the
8 Free Software Foundation; either version 2, or (at your option) any
11 SOPE is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
14 License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with SOPE; see the file COPYING. If not, write to the
18 Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
25 @interface WORadioButton : WOInput
27 // WODynamicElement: extraAttributes
28 // WODynamicElement: otherTagString
33 WOAssociation *selection;
34 WOAssociation *checked;
37 @end /* WORadioButton */
39 @implementation WORadioButton
41 - (id)initWithName:(NSString *)_name
42 associations:(NSDictionary *)_config
43 template:(WOElement *)_t
45 if ((self = [super initWithName:_name associations:_config template:_t])) {
46 self->selection = OWGetProperty(_config, @"selection");
47 self->checked = OWGetProperty(_config, @"checked");
49 if ((self->checked != nil) && (self->value != nil)) {
50 NSLog(@"WARNING: specified both, 'checked' and 'value', "
51 @"associations for radio button!");
58 [self->selection release];
59 [self->checked release];
63 /* handling requests */
65 - (void)takeValuesFromRequest:(WORequest *)_req inContext:(WOContext *)_ctx {
66 WOComponent *sComponent;
69 sComponent = [_ctx component];
70 if ([self->disabled boolValueInComponent:sComponent])
73 // TODO: this seems to have issues
75 // TODO: when a page is called with GET, this overwrites the selection!
76 // - so we should probably only push the value for POST?
78 formValue = [_req formValueForKey:OWFormElementName(self, _ctx)];
80 #warning FIXME, radio button form handling
82 if (self->checked != nil) {
83 // TODO: check needs element-ids?
84 if ([self->checked isValueSettable]) {
85 // TODO: this only checks element-IDs! In case a value is assigned, it
86 // must check the value
87 [self->checked setBoolValue:[formValue isEqual:[_ctx elementID]]
88 inComponent:sComponent];
95 This needs to check the value and compare it with the value of the form,
96 otherwise all radio elements will push the value, multiple times because
97 radio buttons always have the same name!
99 Note that the actual result is usually OK, because all elements push the
100 _same_ value, the one from the form, not their own.
102 if ([self->selection isValueSettable])
103 [self->selection setValue:formValue inComponent:sComponent];
106 /* generating response */
108 - (void)appendToResponse:(WOResponse *)_response inContext:(WOContext *)_ctx {
109 WOComponent *sComponent;
112 sComponent = [_ctx component];
113 lvalue = self->checked
115 : [self->value stringValueInComponent:sComponent];
117 WOResponse_AddCString(_response, "<input type=\"radio\" name=\"");
118 [_response appendContentHTMLAttributeValue:OWFormElementName(self, _ctx)];
119 WOResponse_AddCString(_response, "\" value=\"");
120 [_response appendContentHTMLAttributeValue:lvalue];
121 WOResponse_AddCString(_response, "\"");
123 if (self->checked != nil) {
124 if ([self->checked boolValueInComponent:sComponent]) {
125 WOResponse_AddCString(_response,
126 (_ctx->wcFlags.allowEmptyAttributes
127 ? " checked" : " checked=\"checked\""));
133 v = [self->value valueInComponent:sComponent];
134 sel = [self->selection valueInComponent:sComponent];
135 if ((v == sel) || [v isEqual:sel]) {
136 WOResponse_AddCString(_response,
137 (_ctx->wcFlags.allowEmptyAttributes
138 ? " checked" : " checked=\"checked\""));
142 if ([self->disabled boolValueInComponent:sComponent]) {
143 WOResponse_AddCString(_response,
144 (_ctx->wcFlags.allowEmptyAttributes
145 ? " disabled" : " disabled=\"disabled\""));
148 [self appendExtraAttributesToResponse:_response inContext:_ctx];
149 if (self->otherTagString != nil) {
150 lvalue = [self->otherTagString stringValueInComponent:sComponent];
151 WOResponse_AddChar(_response, ' ');
152 WOResponse_AddString(_response, lvalue);
155 WOResponse_AddEmptyCloseParens(_response, _ctx);
160 - (NSString *)associationDescription {
161 NSMutableString *str = nil;
163 str = [[[super associationDescription] mutableCopy] autorelease];
164 if (self->selection) [str appendFormat:@" selection=%@", self->selection];
165 if (self->checked) [str appendFormat:@" checked=%@", self->checked];
169 @end /* WORadioButton */