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:([v length] > 0) ? v : @"1"];
97 WOResponse_AddCString(_response, "\"");
99 if ([self->disabled boolValueInComponent:[_ctx component]]) {
100 WOResponse_AddCString(_response,
101 (_ctx->wcFlags.allowEmptyAttributes
102 ? " disabled" : " disabled=\"disabled\""));
106 WOResponse_AddCString(_response,
107 (_ctx->wcFlags.allowEmptyAttributes
108 ? " checked" : " checked=\"checked\""));
111 [self appendExtraAttributesToResponse:_response inContext:_ctx];
113 if (self->otherTagString) {
114 WOResponse_AddChar(_response, ' ');
115 WOResponse_AddString(_response,
116 [self->otherTagString stringValueInComponent:
120 if (_ctx->wcFlags.xmlStyleEmptyElements) {
121 WOResponse_AddCString(_response, " />");
124 WOResponse_AddCString(_response, ">");
130 - (NSString *)associationDescription {
131 NSMutableString *str = nil;
132 str = [[NSMutableString alloc]
133 initWithString:[super associationDescription]];
135 if (self->selection) [str appendFormat:@" selection=%@", self->selection];
136 if (self->checked) [str appendFormat:@" checked=%@", self->checked];
138 return [str autorelease];
141 @end /* WOCheckBox */