addWidget() public method

Adds a tag contents to the form.
public addWidget ( SimpleWidget $tag )
$tag SimpleWidget Input tag to add.
 function testPost()
 {
     $form = new SimpleForm(new SimpleFormTag(array('method' => 'post')), $this->page('C:\\Users\\Garen\\Documents\\CS580\\Recipes\\RecipesInLaravel\\public\\testtt.html'));
     $select = new SimpleSelectionTag(array('name' => 'a'));
     $select->addTag(new SimpleOptionTag(array('value' => 'aaa', 'selected' => '')));
     $form->addWidget($select);
     $this->assertIdentical($form->submit(), new SimplePostEncoding(array('a' => 'aaa')));
 }
 function testMultipleFieldsWithSameKey()
 {
     $form = new SimpleForm(new SimpleFormTag(array()), new SimpleUrl('htp://host'));
     $form->addWidget(new SimpleCheckboxTag(array('name' => 'a', 'type' => 'checkbox', 'value' => 'me')));
     $form->addWidget(new SimpleCheckboxTag(array('name' => 'a', 'type' => 'checkbox', 'value' => 'you')));
     $this->assertIdentical($form->getValue(new SimpleByName('a')), false);
     $this->assertTrue($form->setField(new SimpleByName('a'), 'me'));
     $this->assertIdentical($form->getValue(new SimpleByName('a')), 'me');
 }
Beispiel #3
0
 /**
  *  Adds the widget into the form container.
  *  @param object $node             Tidy XML node of widget.
  *  @param SimpleForm $form         Form to add it to.
  *  @param string $enclosing_label  The label of any label
  *                                  tag we might be in.
  */
 private function addWidgetToForm($node, $form, $enclosing_label)
 {
     $widget = $this->tags()->createTag($node->name, $this->attributes($node));
     if (!$widget) {
         return;
     }
     $widget->setLabel($enclosing_label)->addContent($this->innerHtml($node));
     if ($node->name == 'select') {
         $widget->addTags($this->collectSelectOptions($node));
     }
     $form->addWidget($widget);
     $this->indexWidgetById($widget);
 }
Beispiel #4
0
 public function TODO_testRemoveGetParamsFromAction()
 {
     Mock::generatePartial('SimplePage', 'MockPartialSimplePage', array('getUrl'));
     $page = new MockPartialSimplePage();
     $page->returns('getUrl', new SimpleUrl('htp://host/'));
     # Keep GET params in "action", if the form has no widgets
     $form = new SimpleForm(new SimpleFormTag(array('action' => '?test=1')), $page);
     $this->assertEqual($form->getAction()->asString(), 'htp://host/');
     $form = new SimpleForm(new SimpleFormTag(array('action' => '?test=1')), $page);
     $form->addWidget(new SimpleTextTag(array('name' => 'me', 'type' => 'text', 'value' => 'a')));
     $this->assertEqual($form->getAction()->asString(), 'htp://host/');
     $form = new SimpleForm(new SimpleFormTag(array('action' => '')), $page);
     $this->assertEqual($form->getAction()->asString(), 'htp://host/');
     $form = new SimpleForm(new SimpleFormTag(array('action' => '?test=1', 'method' => 'post')), $page);
     $this->assertEqual($form->getAction()->asString(), 'htp://host/?test=1');
 }