1779 Posts in 582 Topics by 556 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 1775 Views |
-
Templating field groups

8 July 2009 at 10:29am
I had a
needwant to have my field groups formatted in fieldsets with legends rather than divs with labels as I believe the former is more semantically useful (ie I know that a fieldset is for grouping similar fields, but I don't know what a div groups).I would have hoped that I would be able to achieve this with a .ss file, but it seems that /sapphire/forms/FieldGroup.php returns HTML directly using the function FieldHolder().
I was able to adjust the HTML code there to get the output I desired, but why isn't it in a template?
-
Re: Templating field groups

9 July 2009 at 7:15pm
It is not in a template as we found early on having each form field in its own template caused a large performance lost, so as a workaround for that its in the php. You could use your own custom subclass of the field to override the template it outputs
-
Re: Templating field groups

17 June 2011 at 1:04pm
I needed to do this for a form which renders dynamic fieldsets from a db query and ended up extending FieldGroup, here is the code if anyone is interested. Very straight-forward and quite specific (needed a table layout) but you can do whatever you want:
<?php
class PublishFieldGroup extends FieldGroup {
function Field() {
$fs = $this->FieldSet();
$spaceZebra = isset($this->zebra) ? " $this->zebra" : '';
$idAtt = isset($this->id) ? " id=\"{$this->id}\"" : '';
$content = "<tr>";
foreach($fs as $subfield) {
$childZebra = (!isset($childZebra) || $childZebra == "odd") ? "even" : "odd";
if($subfield->hasMethod('setZebra')) $subfield->setZebra($childZebra);
$content .= "<td class=\"publishFieldgroupField\">" . $subfield->{$this->subfieldParam}() . "</td>";
}
$content .= "</tr>";
return $content;
}
}
?>
| 1775 Views | ||
|
Page:
1
|
Go to Top |



