WOAssociation *noSelectionString; // WO4
WOAssociation *selectedValue; // WO4.5
WOAssociation *escapeHTML; // WO4.5
+ WOAssociation *itemGroup; // SOPE
}
@end
self->noSelectionString = OWGetProperty(_config, @"noSelectionString");
self->selectedValue = OWGetProperty(_config, @"selectedValue");
self->escapeHTML = OWGetProperty(_config, @"escapeHTML");
+ self->itemGroup = OWGetProperty(_config, @"itemGroup");
if (self->selection != nil && self->selectedValue != nil)
[self logWithFormat:
@"cannot have both 'selection' and 'selectedValue' bindings!"];
- /* compatiblity */
+ /* compatibility */
if (self->noSelectionString == nil)
self->noSelectionString = OWGetProperty(_config, @"nilString");
[self->selection release];
[self->string release];
[self->selectedValue release];
+ [self->itemGroup release];
[super dealloc];
}
object = [objects objectAtIndex:i];
if ([self->item isValueSettable])
- [self->item setValue:object inComponent:sComponent];
+ [self->item setValue:object inComponent:sComponent];
cv = [self->value stringValueInComponent:sComponent];
int i, toGo;
BOOL escapesHTML;
BOOL byVal;
+ id previousGroup = nil;
#if DEBUG
NSTimeInterval st = 0.0;
}
#endif
- if (nilStr) {
+ if (nilStr != nil) {
+ if (self->itemGroup != nil) {
+ id group;
+
+ if ([self->item isValueSettable])
+ [self->item setValue:nil inComponent:sComponent];
+ group = [self->itemGroup stringValueInComponent:sComponent];
+
+ if (group != nil) {
+ WOResponse_AddCString(_response, "<optgroup label=\"");
+ if (escapesHTML) {
+ WOResponse_AddHtmlString(_response, group);
+ }
+ else {
+ WOResponse_AddString(_response, group);
+ }
+ WOResponse_AddCString(_response, "\">");
+ previousGroup = [group retain];
+ }
+ }
WOResponse_AddCString(_response, "<option value=\"");
WOResponse_AddString(_response, WONoSelectionString);
WOResponse_AddCString(_response, "\">");
WOResponse_AddHtmlString(_response, nilStr);
WOResponse_AddCString(_response, "</option>");
+ // FIXME (stephane) Shouldn't we set the 'selected' if selArray/selValueArray is empty?
}
for (i = 0; i < toGo; i++) {
NSString *displayV = nil;
id object;
BOOL isSelected;
+ id group;
#if DEBUG
NSTimeInterval st = 0.0;
? [self->string stringValueInComponent:sComponent]
: [object stringValue];
- if (displayV == nil) displayV = @"<nil>";
+ if (displayV == nil) displayV = (escapesHTML ? @"<nil>" : @"<nil>");
+
+ group = self->itemGroup != nil
+ ? [self->itemGroup stringValueInComponent:sComponent]
+ : nil;
+ if (group != nil) {
+ BOOL groupChanged = NO;
+
+ if (previousGroup == nil)
+ groupChanged = YES;
+ else {
+ if (![group isEqualToString:previousGroup]) {
+ WOResponse_AddCString(_response, "</optgroup>");
+ groupChanged = YES;
+ }
+ }
+ if (groupChanged) {
+ WOResponse_AddCString(_response, "<optgroup label=\"");
+ if (escapesHTML) {
+ WOResponse_AddHtmlString(_response, group);
+ }
+ else {
+ WOResponse_AddString(_response, group);
+ }
+ WOResponse_AddCString(_response, "\">");
+ ASSIGN(previousGroup, group);
+ }
+ }
+ else {
+ if (previousGroup != nil) {
+ WOResponse_AddCString(_response, "</optgroup>");
+ ASSIGN(previousGroup, nil);
+ }
+ }
WOResponse_AddCString(_response, "<option value=\"");
- WOResponse_AddHtmlString(_response, v); // WO escapes it
+ WOResponse_AddHtmlString(_response, v); // WO escapes it, always
WOResponse_AddCString(_response,
isSelected ?
"\" selected=\"selected\">" : "\">");
}
#endif
}
+ if (previousGroup != nil) {
+ WOResponse_AddCString(_response, "</optgroup>");
+ [previousGroup release];
+ }
if ([self->item isValueSettable])
[self->item setValue:nil inComponent:sComponent]; // Reset 'item'
}
[str appendFormat:@" escapeHTML=%@", self->escapeHTML];
if (self->selectedValue)
[str appendFormat:@" selectedValue=%@", self->selectedValue];
+ if (self->itemGroup)
+ [str appendFormat:@" itemGroup=%@", self->itemGroup];
return str;
}