anewt-developers team mailing list archive
-
anewt-developers team
-
Mailing list archive
-
Message #00260
[Branch ~uws/anewt/anewt.uws] Rev 1782: [form] Output additional CSS classes in form renderer output
------------------------------------------------------------
revno: 1782
committer: Wouter Bolsterlee <uws@xxxxxxxxx>
branch nick: anewt.uws
timestamp: Sat 2010-03-27 23:15:25 +0100
message:
[form] Output additional CSS classes in form renderer output
AnewtFormRendererDefault now adds 'form-control-text',
'form-control-button', or 'form-control-choice' CSS class
names to the form control <div> to allow for better styling.
modified:
form/renderer/default.lib.php
--
lp:anewt
https://code.launchpad.net/~uws/anewt/anewt.uws
Your team Anewt developers is subscribed to branch lp:anewt.
To unsubscribe from this branch go to https://code.launchpad.net/~uws/anewt/anewt.uws/+edit-subscription.
=== modified file 'form/renderer/default.lib.php'
--- form/renderer/default.lib.php 2009-04-09 21:16:45 +0000
+++ form/renderer/default.lib.php 2010-03-27 22:15:25 +0000
@@ -82,57 +82,69 @@
{
$control_div = ax_div_class(null, 'form-control');
+ if ($control instanceof AnewtFormControlButton)
+ $control_div->add_class('form-control-button');
+ elseif ($control instanceof AnewtFormControlTextBase)
+ $control_div->add_class('form-control-text');
+ elseif ($control instanceof AnewtFormControlCheckbox || $control instanceof AnewtFormControlChoice)
+ $control_div->add_class('form-control-choice');
+
+
+ /* Description */
+
$control_div->append_child($this->_build_description_node($control));
+
+
+ /* Error message */
+
$control_div->append_child($this->_build_error_node($control));
- /* Label and the widget itself are combined. Buttons do not have
+ /* The label and the widget itself are combined. Buttons do not have
* explicit labels, since the label text is on the button itself. */
$widget = $control->build_widget();
- $label_text = $control->_get('label');
- if (is_null($label_text) || $control instanceof AnewtFormControlButton)
- {
- /* No label (none set or this is a button) */
- $control_div->append_child($widget);
-
- } else
+ $label = $control->_get('label');
+ if ($label && !$control instanceof AnewtFormControlButton)
{
/* This control has a label */
- assert('is_string($label_text) || $label_text instanceof AnewtXMLDomNode');
- $label = new AnewtXHTMLLabel($label_text, array(
+ assert('is_string($label) || $label instanceof AnewtXMLDomNode');
+ $label_node = new AnewtXHTMLLabel($label, array(
'class' => 'form-control',
));
+
/* Some composite widgets support allow the 'for=' attribute to be
* filled in, even though they consist of multiple html widgets. */
+
if ($control->get('composite'))
{
$composite_for = $control->get('composite-for');
if (!is_null($composite_for))
- $label->set_attribute('for', $composite_for);
+ $label_node->set_attribute('for', $composite_for);
}
else
- $label->set_attribute('for', $control->get('id'));
-
-
- /* Help text */
+ {
+ $label_node->set_attribute('for', $control->get('id'));
+ }
+
+
+ /* Help text (optional) */
$help = $control->_get('help');
if (!is_null($help))
{
- $help_text = to_string($help);
- $label->set_attribute('title', $help_text);
- $label->add_class('with-help');
+ $label_node->set_attribute('title', to_string($help_text));
+ $label_node->add_class('with-help');
}
- $control_div->append_child($label);
- $control_div->append_child($widget);
- unset ($label);
+ $control_div->append_child($label_node);
}
- unset ($widget);
+
+ $control_div->append_child($widget);
+
return $control_div;
}