Beispiel #1
0
 public function testAddClass()
 {
     $htmlElement = new \Fiv\Form\Element\Html();
     $currentClassName = $htmlElement->getAttribute('class');
     $this->assertEmpty($currentClassName);
     $htmlElement->addClass('test');
     $this->assertEquals('test', $htmlElement->getAttribute('class'));
     $htmlElement->setAttribute('class', '');
     $this->assertEmpty($htmlElement->getAttribute('class'));
     $htmlElement->setAttribute('class', 'custom_class');
     $this->assertEquals("custom_class", $htmlElement->getAttribute('class'));
     $htmlElement->addClass('other_class');
     $this->assertEquals('custom_class other_class', $htmlElement->getAttribute('class'));
 }
Beispiel #2
0
 /**
  * @return string
  */
 public function render()
 {
     $html = '<button ' . Html::renderAttributes($this->getAttributes()) . ' >';
     $html .= $this->getText() ?: 'Button';
     $html .= '</button>';
     return $html;
 }
Beispiel #3
0
 public function testAttributes()
 {
     $tag = new Html();
     $tag->setTag('input');
     $tag->setAttributes(['value' => 123]);
     $tag->addClass('test');
     $tag->addClass('other');
     $this->assertEquals(['value' => 123, 'class' => 'test other'], $tag->getAttributes());
 }
Beispiel #4
0
 /**
  * @return string
  */
 public function renderStart()
 {
     $hidden = new Element\Input();
     $hidden->setType('hidden');
     $hidden->addAttributes(['name' => $this->getUid()]);
     $hidden->setValue(1);
     # get default attribute
     $method = $this->getMethod();
     $this->setAttribute('method', $method);
     $html = '<form ' . Element\Html::renderAttributes($this->getAttributes()) . '>';
     $html .= $hidden->render();
     # render hidden element
     foreach ($this->getElements() as $element) {
         if ($element instanceof Element\Input and $element->getType() === 'hidden') {
             $html .= $element->render();
         }
     }
     return $html;
 }
Beispiel #5
0
 /**
  * @return string
  */
 public function render()
 {
     return '<textarea ' . Html::renderAttributes($this->getAttributes()) . '>' . $this->getValue() . '</textarea>';
 }
Beispiel #6
0
 /**
  * @inheritdoc
  */
 public function render()
 {
     $value = $this->getValue();
     $this->attributes['value'] = htmlentities($value, ENT_QUOTES);
     return parent::render();
 }