return '';
}
- public function field($boundField, $label)
+ public function field($boundField)
{
if ($boundField->help_text) {
$help_text = Tag::p(array('class' => 'help'))
return $this->errors($boundField->errors) .
Tag::div(array('class' => 'form-row'),
Tag::div()
- ->raw($label)
+ ->raw($boundField->renderLabel())
->raw(' ')
- ->raw($boundField->render())
+ ->raw($boundField->renderWidget())
->append($help_text));
}
$ul = Tag::ul(array('class' => 'errorlist'));
foreach ($errors as $err)
$ul->append(Tag::li(null, $err));
- return Tag::div(null, $ul);
+ return Tag::div(array('class' => 'form-row'), $ul);
}
}
if ($field->widget->is_hidden)
continue;
- $bf = new IPF_Form_BoundField($this, $field, $name);
-
- $label = $field->label;
- if ($this->label_suffix) {
- if (!in_array(mb_substr($label, -1, 1),
- array(':','?','.','!'))) {
- $label .= $this->label_suffix;
- }
- }
-
- if ($field->required)
- $label_attrs = array('class'=>'required');
- else
- $label_attrs = null;
- $label = $bf->labelTag($label, $label_attrs, true);
+ $bf = $this->field($name);
- $output .= $layout->field($bf, $label);
+ $output .= $layout->field($bf);
}
$output .= $layout->endGroup($groupLabel);
}
$this->field = $field;
$this->name = $name;
$this->html_name = $this->form->addPrefix($name);
- if ($this->field->label == '') {
- $this->label = mb_ereg_replace('/\_/', '/ /', mb_ucfirst($name));
- } else {
+
+ if ($this->field->label) {
$this->label = $this->field->label;
+ } else {
+ $this->label = mb_ereg_replace('/\_/', '/ /', mb_ucfirst($name));
+ }
+ if ($this->form->label_suffix && !in_array(mb_substr($this->label, -1, 1), array(':', '?', '.', '!'))) {
+ $this->label .= $this->form->label_suffix;
}
+
$this->help_text = ($this->field->help_text) ? $this->field->help_text : '';
if (isset($this->form->errors[$name])) {
$this->errors = $this->form->errors[$name];
return $this->form->initial($this->name);
}
- public function render()
+ public function renderWidget()
{
$widget = $this->field->widget;
$extra_attrs = array();
- if (array_key_exists('id', $widget->attrs)) {
+ if (!array_key_exists('id', $widget->attrs)) {
$extra_attrs['id'] = $this->autoId();
}
return $widget->render($this->html_name, $this->value(), $extra_attrs);
}
- public function render_w($widget=null, $attrs=array())
- {
- if ($widget === null) {
- $widget = $this->field->widget;
- }
- $id = $this->autoId();
- if ($id and !array_key_exists('id', $attrs)
- and !array_key_exists('id', $widget->attrs)) {
- $attrs['id'] = $id;
- }
-
- $code = $widget->render($this->html_name, $this->value(), $attrs);
-
- return $this->form->unescape($code);
- }
-
- public function labelTag($contents=null, $attrs=null, $raw=false)
+ public function renderLabel()
{
- $label = Tag::label($attrs);
-
- if ($contents)
- $label->raw($contents);
- else
- $label->append($this->label);
+ $label = Tag::label()
+ ->append($this->label);
$widget = $this->field->widget;
$id = (isset($widget->attrs['id'])) ? $widget->attrs['id'] : $this->autoId();
$label->attr('for', $widget->idForLabel($id));
- if ($raw)
- return $label->html();
- else
- return $this->form->unescape($label->html());
+ if ($this->field->required)
+ $label->addClass('required');
+
+ return $label->html();
}
public function autoId()
return '';
}
+
+ public function labelTag()
+ {
+ return $this->form->unescape($this->renderLabel());
+ }
+
+ public function render_w()
+ {
+ return $this->form->unescape($this->renderWidget());
+ }
+
public function fieldErrors($raw=false)
{
$errors = IPF_Form::renderErrorsAsHTML($this->errors);
{
public function startForm($form);
public function startGroup($label);
- public function field($boundField, $label);
+ public function field($boundField);
public function endGroup($label);
public function endForm($form);
}*/
{
public function startForm($form) { return ''; }
public function startGroup($label) { return ''; }
- public abstract function field($boundField, $label);
+ public abstract function field($boundField);
public function endGroup($label) { return ''; }
public function endForm($form) { return ''; }
{
$hiddenWidgets = '';
foreach ($form->hiddenFields() as $field_name)
- $hiddenWidgets .= $form->field($field_name)->render();
+ $hiddenWidgets .= $form->field($field_name)->renderWidget();
return $hiddenWidgets;
}
return $o;
}
- public function field($boundField, $label)
+ public function field($boundField)
{
return
$this->errorList($boundField->errors) .
Tag::p()
- ->raw($label)
+ ->raw($boundField->renderLabel())
->raw(' ')
- ->raw($boundField->render())
+ ->raw($boundField->renderWidget())
->raw(' ')
->raw($boundField->help_text);
}
return '';
}
- public function field($boundField, $label)
+ public function field($boundField)
{
if ($boundField->help_text)
$help_text = '<br /><span class="helptext">'.$boundField->help_text.'</span>';
return Tag::li()
->raw($this->takeDeferred())
->raw($this->errorList($boundField->errors))
- ->raw($label)
+ ->raw($boundField->renderLabel())
->raw(' ')
- ->raw($boundField->render())
+ ->raw($boundField->renderWidget())
->raw($help_text);
}
return '';
}
- public function field($boundField, $label)
+ public function field($boundField)
{
if ($boundField->help_text)
$help_text = '<br /><span class="helptext">'.$boundField->help_text.'</span>';
return Tag::tr(null,
Tag::th()
- ->raw($label),
+ ->raw($boundField->renderLabel()),
Tag::td()
->raw($this->takeDeferred())
->raw($this->errorList($boundField->errors))
- ->raw($boundField->render())
+ ->raw($boundField->renderWidget())
->raw($help_text));
}