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 WOCheckBox : WOInput
27 // WODynamicElement: extraAttributes
28 // WODynamicElement: otherTagString
31 // inherited: disabled
33 WOAssociation *selection;
34 WOAssociation *checked;
39 @implementation WOCheckBox
41 - (id)initWithName:(NSString *)_name
42 associations:(NSDictionary *)_config
43 template:(WOElement *)_c
45 if ((self = [super initWithName:_name associations:_config template:_c])) {
46 self->selection = OWGetProperty(_config, @"selection");
47 self->checked = OWGetProperty(_config, @"checked");
53 [self->selection release];
54 [self->checked release];
58 /* handling requests */
60 - (void)takeValuesFromRequest:(WORequest *)_rq inContext:(WOContext *)_ctx {
62 Checkboxes are special in their form-value handling. If the form is
63 submitted and the checkbox is checked, a 'YES' value is transferred in the
64 request. If the checkbox is not-checked, no value is transferred at all !
68 if ([self->disabled boolValueInComponent:[_ctx component]])
71 formValue = [_rq formValueForKey:OWFormElementName(self, _ctx)];
73 if ([self->checked isValueSettable]) {
74 [self->checked setBoolValue:formValue ? YES : NO
75 inComponent:[_ctx component]];
78 if ([self->value isValueSettable] && (formValue != nil))
79 [self->value setStringValue:formValue inComponent:[_ctx component]];
82 - (void)appendToResponse:(WOResponse *)_response inContext:(WOContext *)_ctx {
86 if ([[_ctx request] isFromClientComponent])
89 v = [self->value stringValueInComponent:[_ctx component]];
90 isChecked = [self->checked boolValueInComponent:[_ctx component]];
92 WOResponse_AddCString(_response, "<input type=\"checkbox\" name=\"");
93 [_response appendContentHTMLAttributeValue:
94 OWFormElementName(self, _ctx)];
95 WOResponse_AddCString(_response, "\" value=\"");
96 [_response appendContentHTMLAttributeValue:
97 ([v isNotEmpty] ? v : (NSString *)@"1")];
98 WOResponse_AddCString(_response, "\"");
100 if ([self->disabled boolValueInComponent:[_ctx component]]) {
101 WOResponse_AddCString(_response,
102 (_ctx->wcFlags.allowEmptyAttributes
103 ? " disabled" : " disabled=\"disabled\""));
107 WOResponse_AddCString(_response,
108 (_ctx->wcFlags.allowEmptyAttributes
109 ? " checked" : " checked=\"checked\""));
112 [self appendExtraAttributesToResponse:_response inContext:_ctx];
114 if (self->otherTagString) {
115 WOResponse_AddChar(_response, ' ');
116 WOResponse_AddString(_response,
117 [self->otherTagString stringValueInComponent:
121 if (_ctx->wcFlags.xmlStyleEmptyElements) {
122 WOResponse_AddCString(_response, " />");
125 WOResponse_AddCString(_response, ">");
131 - (NSString *)associationDescription {
132 NSMutableString *str = nil;
133 str = [[NSMutableString alloc]
134 initWithString:[super associationDescription]];
136 if (self->selection) [str appendFormat:@" selection=%@", self->selection];
137 if (self->checked) [str appendFormat:@" checked=%@", self->checked];
139 return [str autorelease];
142 @end /* WOCheckBox */