Пример #1
0
 /**
  * Render element
  *
  * @param Zend_Form_Element $element
  * @return string
  */
 public function aElement(Zend_Form_Element $element)
 {
     $viewClasses = array($element->getAttrib('class'));
     if ($element->isRequired()) {
         if (!$element->getAttrib('title')) {
             $element->setAttrib('title', 'Field is required');
         }
         $viewClasses[] = 'aForm-field-required';
     }
     if ($element->getValidators()) {
         $viewClasses[] = 'aForm-field-validate';
     }
     if ($element->hasErrors()) {
         $viewClasses[] = 'aForm-field-invalid';
     } elseif ($element->getValue() || !$element->isRequired()) {
         $viewClasses[] = 'aForm-field-valid';
     }
     if ($element->getValidators()) {
         $viewClasses[] = 'aForm-field-validate';
     }
     $element->setAttrib('class', implode(' ', $viewClasses));
     $options = null;
     $separator = null;
     if ($element instanceof Zend_Form_Element_Multi) {
         $options = $element->getMultiOptions();
         $separator = $element->getSeparator();
     }
     return $this->view->{$element->helper}($element->getName(), $element->getValue(), $element->getAttribs(), $options, $separator);
 }
Пример #2
0
 /**
  * Adds default decorators to an existing element
  * 
  * @param Zend_Form_Element $element
  */
 public static function addDefaultDecorators(Zend_Form_Element $element)
 {
     $fqName = $element->getName();
     if (null !== ($belongsTo = $element->getBelongsTo())) {
         $fqName = $belongsTo . '-' . $fqName;
     }
     $element->addDecorator('Description', array('tag' => 'p', 'class' => 'description', 'placement' => 'PREPEND'))->addDecorator('HtmlTag', array('tag' => 'div', 'id' => $fqName . '-element', 'class' => 'form-element'))->addDecorator('Label', array('tag' => 'div', 'tagOptions' => array('id' => $fqName . '-label', 'class' => 'form-label')))->addDecorator('HtmlTag2', array('tag' => 'div', 'id' => $fqName . '-wrapper', 'class' => 'form-wrapper'));
 }
Пример #3
0
 public function renderLabel(Zend_Form_Element $element, Zend_View_Interface $view)
 {
     $label = $element->getLabel();
     if (empty($label)) {
         $label = $element->getName();
     }
     return '<div class="pointer" onClick = goToErrorLabel(\'' . $element->getId() . '\')>' . $this->getMarkupElementLabelStart() . $view->escape($label) . $this->getMarkupElementLabelEnd() . '</div>';
 }
 /**
  * Setup per-element properties like labels, and classes
  */
 protected function setupSingleElement(Zend_Form_Element $elm)
 {
     // determine if this element has an error. (Will be used below)
     $elmHasError = count($elm->getMessages()) > 0;
     // set element values from the language pack
     $elm->setLabel($this->lang->get('form.label.' . $elm->getName()));
     // display info about required length if validator exists
     if ($elm->getValidator('StringLength')) {
         $elm->setDescription(sprintf($this->lang->get('form.description.' . $elm->getName()), $elm->getValidator('StringLength')->getMin(), $elm->getValidator('StringLength')->getMax()));
     } else {
         $elm->setDescription($this->lang->get('form.description.' . $elm->getName()));
     }
     // Duplicating type attr to classname in case we need to support IE6
     // and want to be able to directly target the element without using
     // input[type=text]
     $zendType = $elm->getType();
     $className = strtolower(substr($zendType, strrpos($zendType, '_') + 1));
     $elm->setAttrib('class', $className);
     // wrap this stuff up in a html div with class 'element'
     $elm->addDecorator('HtmlTag', array('tag' => 'div', 'class' => 'element'));
     // determine if element has error and use that to determine prefix char.
     // 1. There seems to be no way to add html to the reqPrefix
     // 2. There seems to be no way to add a custom classname to the div tag
     if ($elm->getName() != 'submit') {
         $reqChar = $elmHasError ? '! ' : '* ';
         $elm->addDecorator('Label', array('placement' => 'prepend', 'tag' => 'div', 'requiredPrefix' => $reqChar));
     }
     // use custom error decorator that attempts to replace default error
     // messages by the ones supplied by My_LanguagaPack
     $errorDecorator = new My_Decorator_Errors();
     $errorDecorator->setLanguagePack($this->lang);
     $elm->addDecorator($errorDecorator);
     // wrap everything so far in a li tag, give it class error if elm has error
     // ATT: using array to create alias for allready used HtmlTag decorator
     $liClass = $elmHasError ? 'error' : '';
     $elm->addDecorator(array('outerLi' => 'HtmlTag'), array('tag' => 'li', 'class' => $liClass));
 }
 /**
  * Enter description here ...
  * @param Zend_Form_Element $element
  * @author Tung Ly
  */
 public function renderFormElement($element, $vertical = 0)
 {
     if ($element->getType() != "Zend_Form_Element_Checkbox") {
         $element->setAttrib('class', $element->getAttrib('class') . ' form-control');
     }
     if ($element->isRequired()) {
         $element->setLabel($element->getLabel() . ' *');
         $element->setAttrib('class', $element->getAttrib('class') . ' required');
     }
     switch ($element->getType()) {
         case 'Zend_Form_Element_Textarea':
             $element->setAttrib('rows', 5);
             $element->setAttrib('cols', 80);
             break;
         case 'Zend_Form_Element_Hidden':
             return $element;
         default:
             break;
     }
     $error = '';
     if ($element->hasErrors()) {
         $error = 'has-error';
     }
     if ($element->getType() == 'Zend_Form_Element_Textarea') {
     }
     $btn = array('Zend_Form_Element_Submit', 'Zend_Form_Element_Reset');
     if (in_array($element->getType(), $btn)) {
         //$t ='<button type="reset" class="btn"><i class="icon-refresh"></i> '.$element->getLabel().'</button>';
         $t = '<div class="span2">' . $element . '</div>';
     } else {
         $label = trim(preg_replace("/([A-Z])/", " \$1", "{$element->getLabel()}"), ' ');
         $variables = array('%%ERROR_CLASS%%' => $error, '%%ELEMENT_NAME%%' => $element->getName(), '%%ELEMENT_LABEL%%' => $label, '%%ELEMENT%%' => $element, '%%HELP_MESSAGE%%' => current($element->getMessages()));
         $t = str_replace(array_keys($variables), $variables, $this->_getTemplate($vertical));
     }
     return $t;
 }
Пример #6
0
 /**
  * Add element to stack
  *
  * @param  Zend_Form_Element $element
  * @return Zend_Form_DisplayGroup
  */
 public function addElement(Zend_Form_Element $element)
 {
     $this->_elements[$element->getName()] = $element;
     $this->_groupUpdated = true;
     // Display group will now handle display of element
     if (null !== ($form = $this->getForm())) {
         $form->removeFromIteration($element->getName());
     }
     return $this;
 }
Пример #7
0
 public function testPassingConfigObjectToConstructorSetsObjectState()
 {
     $config = new Zend_Config($this->getOptions());
     $element = new Zend_Form_Element($config);
     $this->assertEquals('changed', $element->getName());
     $this->assertEquals('foo', $element->getValue());
     $this->assertEquals('bar', $element->getLabel());
     $this->assertEquals(50, $element->getOrder());
     $this->assertFalse($element->isRequired());
     $this->assertEquals('bar', $element->foo);
     $this->assertEquals('bat', $element->baz);
 }
Пример #8
0
 public function decorateConfig($content, Zend_Form_Element $element, array $options)
 {
     $view = $this->getView();
     $value = $view->escape($element->getValue());
     return '<textarea name="' . $view->escape($element->getName()) . '"' . ' class="f-max-size" readonly="readonly"' . ' id="' . $view->escape($element->getId()) . '"' . ' rows="' . (substr_count($value, "\n") + 1) . '" cols="80" style="width: 100%;"' . '>' . $value . '</textarea>';
 }
Пример #9
0
 /**
  * 
  * @param Zend_Form_Element $element
  * @return string[]
  */
 private function _getDefaultElementDecorator(Zend_Form_Element $element)
 {
     $decorator = array();
     if ($element instanceof Zend_Form_Element_Checkbox) {
         $decorator[] = array(array('Label-Open' => 'HtmlTag'), array('tag' => 'label', 'class' => 'checkbox', 'id' => $element->getId() . '-label', 'for' => $element->getName(), 'openOnly' => true));
         $decorator[] = 'ViewHelper';
         $decorator[] = array('CheckBoxLabel');
         $decorator[] = array(array('Label-Closing' => 'HtmlTag'), array('tag' => 'label', 'closeOnly' => true));
         $decorator[] = array('Errors', array('placement' => 'append'));
         $decorator[] = array('Description', array('tag' => 'span', 'class' => 'help-block'));
         $decorator[] = array(array('Inner-Wrapper' => 'HtmlTag'), array('tag' => 'div', 'class' => 'col-sm-10'));
         $decorator[] = array(array('Outer-Wrapper' => 'HtmlTag'), array('tag' => 'div', 'class' => 'form-group'));
         return $decorator;
     }
     if ($element instanceof Zend_Form_Element_Submit || $element instanceof Zend_Form_Element_Reset || $element instanceof Zend_Form_Element_Button) {
         $decorator[] = 'ViewHelper';
         return $decorator;
     }
     if ($element instanceof Zend_Form_Element_File) {
         $decorator[] = 'File';
         $decorator[] = 'Errors';
         $decorator[] = array('Description', array('tag' => 'span', 'class' => 'input-file', 'placement' => 'prepend'));
         $decorator[] = array(array('File-Wrapper' => 'HtmlTag'), array('tag' => 'span', 'class' => 'btn btn-default'));
     } else {
         $decorator[] = 'ViewHelper';
         $decorator[] = 'Errors';
         $decorator[] = array('Description', array('tag' => 'span', 'class' => 'help-block'));
     }
     if ($this->_type === self::TYPE_HORIZONTAL) {
         $decorator[] = array(array('Inner-Wrapper' => 'HtmlTag'), array('tag' => 'div', 'class' => 'col-sm-10'));
         $decorator[] = array('Label', array('class' => 'control-label col-sm-2'));
         $decorator[] = array(array('Outer-Wrapper' => 'HtmlTag'), array('tag' => 'div', 'class' => 'form-group'));
     } else {
         $decorator[] = 'Label';
         $decorator[] = array('HtmlTag', array('tag' => 'div', 'class' => 'form-group'));
     }
     return $decorator;
 }
Пример #10
0
 /**
  * Render element label
  *
  * @param  Zend_Form_Element $element
  * @param  Zend_View_Interface $view
  * @return string
  */
 public function renderLabel(Zend_Form_Element $element, Zend_View_Interface $view)
 {
     $label = $element->getLabel();
     if (empty($label)) {
         $label = $element->getName();
         // Translate element name
         if (null !== ($translator = $element->getTranslator())) {
             $label = $translator->translate($label);
         }
     }
     if ($this->getEscape()) {
         $label = $view->escape($label);
     }
     return $this->getMarkupElementLabelStart() . $label . $this->getMarkupElementLabelEnd();
 }
 /**
  * Returns the name of the compared element.
  *
  * @return string
  */
 protected function getCompareName()
 {
     return $this->element->getName();
 }
Пример #12
0
 /**
  * Static function that adds all the elements in 1 wrapping element instead of dt, dd structure
  *
  * @param $elm
  * @return void
  */
 public static function setElementDecorator(Zend_Form_Element $elm)
 {
     $elm->addPrefixPath('Glitch_Form_Decorator', 'Glitch/Form/Decorator/', 'decorator');
     $labelSettings = array();
     if ($elm->getDecorator('Label')) {
         $labelSettings = $elm->getDecorator('Label')->getOptions();
         unset($labelSettings['tag']);
         //Tag should never be needed when you call this method
     }
     $class = 'wrapper';
     if ($elm->getAttrib('wrapperClass')) {
         $class .= ' ' . $elm->getAttrib('wrapperClass');
         $elm->setAttrib('wrapperClass', null);
     }
     if ($elm instanceof Zend_Form_Element_Hidden) {
         $class .= ' hidden';
     }
     $elm->clearDecorators()->addDecorator('Label', $labelSettings)->addDecorator('ViewHelper')->addDecorator('Description', array('escape' => false))->addDecorator('Errors')->addDecorator('Wrapper', array('tag' => 'div', 'id' => $elm->getName() . '-wrapper', 'class' => $class));
     if ($elm instanceof Zend_Form_Element_Submit) {
         $elm->removeDecorator('Label');
     }
 }
 /**
  * Adiciona o elemento na lista para ser renderizado somente quando necessário
  *
  * @param Zend_Form_Element $oElemento
  * @throws Exception
  */
 public function addCampo(Zend_Form_Element $oElemento)
 {
     $sNome = $oElemento->getName();
     if (!isset(self::$aCampos[$sNome])) {
         self::$aCampos[$sNome] = $oElemento;
     } else {
         throw new Exception(self::$oTranslate->_(sprintf('O elemento "%s" já foi adicionado no formulário.', $sNome)));
     }
 }
Пример #14
0
 public function addElement(Zend_Form_Element $element)
 {
     $this->_elements[$element->getName()] = $element;
 }
Пример #15
0
 /**
  * Render element label
  *
  * @param  Zend_Form_Element $element
  * @param  Zend_View_Interface $view
  * @return string
  */
 public function renderLabel(Zend_Form_Element $element, Zend_View_Interface $view)
 {
     $label = $element->getLabel();
     if (empty($label)) {
         $label = $element->getName();
     }
     return $this->getMarkupElementLabelStart() . $view->escape($label) . $this->getMarkupElementLabelEnd();
 }
Пример #16
0
 /**
  * Generate the JavaScript code for the validation rules
  * @param Zend_Form_Element $element
  * @return string
  */
 protected function _generateValidationRules(Zend_Form_Element $element)
 {
     $name = $element->getName();
     $formName = $this->_formName;
     $validators = $element->getValidators();
     $rules = array();
     foreach ($validators as $validator) {
         $class = get_class($validator);
         $params = $this->_generateValidatorParameters($class, $validator);
         $rules[] = "{ name: '{$class}', parameters: {$params} }";
     }
     if (count($rules) > 0) {
         $script = $this->_formNamespace . "." . $this->_formName . ".{$name} = [ " . implode(', ', $rules) . " ];\r\n";
     }
     return $script;
 }
 /**
  * Gets form element html
  *
  * @param Zend_Form_Element $element
  * @return string 
  */
 protected function getInputHTML($element)
 {
     $helper = $element->helper;
     $elBelongsTo = $element->getBelongsTo();
     if (!empty($this->belongsTo)) {
         $name = $this->mergeBelongsTo($this->belongsTo, $element->getBelongsTo());
         $name .= '[' . $element->getName() . ']';
     } else {
         if (!empty($elBelongsTo)) {
             $name = $this->mergeBelongsTo($elBelongsTo, $element->getName());
         } else {
             $name = $element->getName();
         }
     }
     $value = $element->getValue();
     //echo 'Name:'.$name.' | Class:'.  get_class($element).' | Helper:'.$helper.'['.$value.']'.'<br/>';
     return $element->getView()->{$helper}($name, $value, $element->getAttribs(), $element->options);
 }
Пример #18
0
Файл: Form.php Проект: abdala/la
 /**
  *
  * @param Zend_Form_Element|string $element
  * @return Zend_Form_Element 
  */
 public function replaceElement($element)
 {
     $name = $element->getName();
     $previousElement = $this->getElement($name);
     if ($previousElement) {
         $label = $this->getElement($name)->getLabel();
         $element->setLabel($label);
     }
     $this->addElement($element);
     return $this;
 }
Пример #19
0
 public static function element2id(\Zend_Form_Element $element)
 {
     return self::name2id($element->getName(), $element->getBelongsTo());
 }
Пример #20
0
 /**
  * Add element to stack
  * 
  * @param  Zend_Form_Element $element 
  * @return Zend_Form_DisplayGroup
  */
 public function addElement(Zend_Form_Element $element)
 {
     $this->_elements[$element->getName()] = $element;
     $this->_groupUpdated = true;
     return $this;
 }
 /**
  * Default button creation function.
  *
  * @param \Zend_Form_Element $button or null
  * @param string $buttonId
  * @param string $label
  * @param string $defaultLabel
  * @param string $class
  */
 protected function _addButton(&$button, &$buttonId, &$label, $defaultLabel, $class = 'Zend_Form_Element_Submit')
 {
     if ($button && $button instanceof \Zend_Form_Element) {
         $buttonId = $button->getName();
     } elseif ($buttonId) {
         //If already there, get a reference button
         $button = $this->_form->getElement($buttonId);
         if (!$button) {
             if (null === $label) {
                 $label = $defaultLabel;
             }
             $button = new $class($buttonId, $label);
             if ($this->buttonClass) {
                 $button->setAttrib('class', $this->buttonClass);
             }
             // Make sure no DD / DT parts are on display
             $button->setDecorators(array('Tooltip', 'ViewHelper'));
         }
     }
     if (!$this->_form->getElement($buttonId)) {
         $this->_form->addElement($button);
     }
 }