Exemple #1
0
 /**
  * @param \DOMElement $node
  */
 private function createField(\DOMElement $node)
 {
     if (!$node->hasAttribute('name') || !$node->getAttribute('name')) {
         return;
     }
     $nodeName = $node->nodeName;
     if ('select' == $nodeName) {
         $this->addField(new Field\SelectFormField($node));
     } elseif ('input' == $nodeName and 'checkbox' == strtolower($node->getAttribute('type'))) {
         $this->addField(new Field\CheckBoxFormField($node));
     } elseif ('input' == $nodeName and 'radio' == strtolower($node->getAttribute('type'))) {
         // there may be other fields with the same name that are no choice
         if ($this->hasField($node->getAttribute('name')) and $this->getField($node->getAttribute('name')) instanceof Field\RadioGroup) {
             $this->getField($node->getAttribute('name'))->addChoice($node);
         } else {
             $radioGroup = new Field\RadioGroup($node->getAttribute('name'));
             $radioGroup->addChoice($node);
             $this->addField($radioGroup);
         }
     } elseif ('input' == $nodeName and 'file' == strtolower($node->getAttribute('type'))) {
         $this->addField(new Field\FileFormField($node));
     } elseif ('input' == $nodeName and !in_array(strtolower($node->getAttribute('type')), array('submit', 'button', 'image'))) {
         $this->addField(new Field\InputFormField($node));
     } elseif ('textarea' == $nodeName) {
         $this->addField(new Field\TextareaFormField($node));
     }
 }
 public function testIsDisabled()
 {
     $field = new RadioGroup('foo');
     $option = $this->createNode('input', '', array('type' => 'radio', 'name' => 'name', 'value' => 'foo', 'disabled' => 'disabled'));
     $field->addChoice($option);
     $option = $this->createNode('input', '', array('type' => 'radio', 'name' => 'name', 'value' => 'bar'));
     $field->addChoice($option);
     $option = $this->createNode('input', '', array('type' => 'radio', 'name' => 'name', 'value' => 'baz', 'disabled' => ''));
     $field->addChoice($option);
     // ->getValue() returns the value attribute of the selected radio button
     $field->select('foo');
     $this->assertEquals('foo', $field->getValue());
     $this->assertTrue($field->isDisabled());
     // ->getValue() returns the value attribute of the selected radio button
     $field->select('bar');
     $this->assertEquals('bar', $field->getValue());
     $this->assertFalse($field->isDisabled());
     // ->getValue() returns the value attribute of the selected radio button
     $field->select('baz');
     $this->assertEquals('baz', $field->getValue());
     $this->assertTrue($field->isDisabled());
 }