/** * Sets the layout to the use of html elements * * @see \MUtil_Html * * @param string $html HtmlTag for element or empty sequence when empty * @param string $args \MUtil_Ra::args additional arguments for element * @return \MUtil_Form (continuation pattern) */ public function setHtml($html = null, $args = null) { $options = \MUtil_Ra::args(func_get_args(), 1); if ($html instanceof \MUtil_Html_ElementInterface) { if ($options) { foreach ($options as $name => $option) { if (is_int($name)) { $html[] = $option; } else { $html->{$name} = $option; } } } } elseif (null == $html) { $html = new \MUtil_Html_Sequence($options); } else { $html = \MUtil_Html::createArray($html, $options); } if ($html instanceof \MUtil_Html_FormLayout) { $html->setAsFormLayout($this); } else { // Set this element as the form decorator $decorator = new \MUtil_Html_ElementDecorator(); $decorator->setHtmlElement($html); // $decorator->setPrologue($formrep); // Renders hidden elements before this element $this->setDecorators(array($decorator, 'AutoFocus', 'Form')); } $this->_html_element = $html; return $this; }
/** * Apply this element to the form as the output decorator. * * @param \Zend_Form $form * @param mixed $width The style.width content for the labels * @param array $order The display order of the elements * @param string $errorClass Class name to display all errors in * @return \MUtil_Html_DlElement */ public function setAsFormLayout(\Zend_Form $form, $width = null, $order = array('label', 'element', 'description'), $errorClass = 'errors') { $this->_repeatTags = true; $prependErrors = $errorClass; // Make a Lazy repeater for the form elements and set it as the element repeater $formrep = new \MUtil_Lazy_RepeatableFormElements($form); $formrep->setSplitHidden(true); // These are treated separately $this->setRepeater($formrep); if (null === $width) { $attr = array(); } else { $attr['style'] = array('display' => 'inline-block', 'width' => $width); } // Place the choosen renderers foreach ($order as $renderer) { switch ($renderer) { case 'label': $this->label($formrep->element, $attr); // Set label with optional width break; case 'error': $prependErrors = false; // Intentional fall through // Intentional fall through default: $this->append($formrep->{$renderer}); } } // Set this element as the form decorator $decorator = new \MUtil_Html_ElementDecorator(); $decorator->setHtmlElement($this); $decorator->setPrologue($formrep); // Renders hidden elements before this element if ($prependErrors) { $decorator->setPrependErrors(\MUtil_Html_ListElement::ul(array('class' => $errorClass, 'style' => array('margin-left' => $width)))); } $form->setDecorators(array($decorator, 'AutoFocus', 'Form')); return $this; }
/** * Apply this element to the form as the output decorator. * * @param \Zend_Form $form * @param mixed $width The style.width content for the labels * @param array $order The display order of the elements * @return \MUtil_Html_DlElement */ public function setAsFormLayout(\Zend_Form $form, $width = null, array $order = array('element', 'errors', 'description')) { // Make a Lazy repeater for the form elements and set it as the element repeater $formrep = new \MUtil_Lazy_RepeatableFormElements($form); $formrep->setSplitHidden(true); // These are treated separately $this->setRepeater($formrep); if (null === $width) { $attr = array(); } else { $attr['style'] = array('width' => $width); } $this->dt()->label($formrep->element, $attr); // Set label dt with optional width $dd = $this->dd(); foreach ($order as $renderer) { $dd[] = $formrep->{$renderer}; } // $this->dd($formrep->element, ' ', $formrep->errors, ' ', $formrep->description); // $this->dd($formrep->element, $formrep->description, $formrep->errors); // Set this element as the form decorator $decorator = new \MUtil_Html_ElementDecorator(); $decorator->setHtmlElement($this); $decorator->setPrologue($formrep); // Renders hidden elements before this element $form->setDecorators(array($decorator, 'AutoFocus', 'Form')); return $this; }