public function getForm() { $form = new Form(); $form->addElement('text', 'foo')->addElement('text', 'bar')->addElement('text', 'baz')->addElement('text', 'bat'); $subForm = new SubForm(); $subForm->addElement('text', 'foo')->addElement('text', 'bar')->addElement('text', 'baz')->addElement('text', 'bat'); $form->addDisplayGroup(array('foo', 'bar'), 'foobar')->addSubForm($subForm, 'sub')->setView(new View\PhpRenderer()); return $form; }
public function setupForm() { $form1 = new SubForm(); $form1->addElement('text', 'foo', array('label' => 'Sub Foo: ', 'required' => true, 'validators' => array('NotEmpty', 'Alpha')))->addElement('text', 'bar', array('label' => 'Sub Bar: ', 'required' => true, 'validators' => array('Alpha', 'Alnum'))); $form2 = new Form(); $form2->addElement('text', 'foo', array('label' => 'Master Foo: ', 'required' => true, 'validators' => array('NotEmpty', 'Alpha')))->addElement('text', 'bar', array('required' => true, 'validators' => array('Alpha', 'Alnum')))->addSubForm($form1, 'sub'); $form2->isValid(array('foo' => '', 'bar' => 'foo 2 u 2', 'sub' => array('foo' => '', 'bar' => 'foo 2 u 2'))); $form2->setView($this->getView()); $this->decorator->setElement($form2); $this->form = $form2; return $form2; }
public function prepareForm() { $sub1 = new SubForm(); $sub1->addElement('text', 'foo') ->addElement('text', 'bar'); $this->form->setElementsBelongTo('foo') ->addElement('text', 'foo') ->addElement('text', 'bar') ->addElement('text', 'baz') ->addElement('text', 'bat') ->addDisplayGroup(array('baz', 'bat'), 'bazbat') ->addSubForm($sub1, 'sub') ->setView($this->getView()); }
/** * Get view * * @return \Zend\View\ViewEngine */ public function getView() { $view = parent::getView(); if (!$this->_dojoViewPathRegistered) { if (false === $view->getPluginLoader('helper')->getPaths('Zend\\Dojo\\View\\Helper')) { $view->addHelperPath('Zend/Dojo/View/Helper', 'Zend\\Dojo\\View\\Helper'); } $this->_dojoViewPathRegistered = true; } return $view; }
/** * Get view * * @return \Zend\View\Renderer */ public function getView() { $view = parent::getView(); if (!$this->_dojoViewPathRegistered) { if (false === $view->getBroker()->isLoaded('dojo')) { $loader = new \Zend\Dojo\View\HelperLoader(); $view->getBroker()->getClassLoader()->registerPlugins($loader); } $this->_dojoViewPathRegistered = true; } return $view; }
public function testMultiFileWithOneFile() { $form = new Form(); $element = new FileElement('file'); $element->setMultiFile(1); $subform0 = new SubForm(); $subform0->addElement($element); $subform1 = new SubForm(); $subform1->addSubform($subform0, 'subform0'); $subform2 = new SubForm(); $subform2->addSubform($subform1, 'subform1'); $subform3 = new SubForm(); $subform3->addSubform($subform2, 'subform2'); $form->addSubform($subform3, 'subform3'); $form->setView(new View()); $output = (string) $form; $this->assertNotContains('name="file[]"', $output); }
/** * @group ZF-7134 * @group ZF-7266 */ public function testComboBoxInSubFormShouldCreateJsonStoreBasedOnQualifiedId() { DojoHelper::setUseProgrammatic(); $this->element->setStoreId('foo')->setStoreType('dojo.data.ItemFileReadStore')->setStoreParams(array('url' => '/foo')); $subform = new SubForm(array('name' => 'bar')); $subform->addElement($this->element); $html = $this->element->render(); $dojo = $this->view->dojo()->__toString(); $this->assertContains('"store":"foo"', $dojo, $dojo); }
/** * @group ZF-11831 */ public function testElementsOfSubFormReceiveCorrectDefaultTranslator() { $isEmptyKey = \Zend\Validator\NotEmpty::IS_EMPTY; // Global default translator $trDefault = new Translator(array('adapter' => 'arrayAdapter', 'content' => array($isEmptyKey => 'Default'), 'locale' => 'en')); Registry::set('Zend_Translate', $trDefault); // Translator to use for elements $trElement = new Translator(array('adapter' => 'arrayAdapter', 'content' => array($isEmptyKey => 'Element'), 'locale' => 'en')); \Zend\Validator\AbstractValidator::setDefaultTranslator($trElement); // Change the form's translator $form = new Form(); $form->addElement(new \Zend\Form\Element\Text('foo', array('required' => true, 'validators' => array('NotEmpty')))); // Create a subform with it's own validator $sf1 = new SubForm(); $sf1->addElement(new \Zend\Form\Element\Text('foosub', array('required' => true, 'validators' => array('NotEmpty')))); $form->addSubForm($sf1, 'Test1'); $form->isValid(array()); $messages = $form->getMessages(); $this->assertEquals('Element', @$messages['foo'][$isEmptyKey], 'Form element received wrong validator'); $this->assertEquals('Element', @$messages['Test1']['foosub'][$isEmptyKey], 'SubForm element received wrong validator'); }
/** * @group ZF-8494 */ public function testGetValidSubFormValues() { $data = array('sub' => array('valid' => 1234, 'invalid' => 'invalid', 'noElement' => 'noElement')); $subForm = new \Zend\Form\SubForm(); $validElement = new \Zend\Form\Element("valid"); $validElement->addValidator(new \Zend\Validator\Int()); $subForm->addElement($validElement); $invalidElement = new \Zend\Form\Element('invalid'); $invalidElement->addValidator(new \Zend\Validator\Int()); $subForm->addElement($invalidElement); $this->form->addSubForm($subForm, 'sub'); $this->assertEquals(array('sub' => array('valid' => 1234)), $this->form->getValidValues($data)); }
/** * @group ZF-7054 */ public function testCustomIdSupersedesElementId() { $form = new SubForm(); $form->setName('bar') ->setView($this->getView()); $html = $this->decorator->setElement($form) ->setOption('id', 'foo-id') ->render('content'); $this->assertContains('foo-id', $html); }
public function testEachSubFormShouldBePrepared() { $subForm = new SubForm(); $subSubForm = new SubForm(); $subForm->addSubForm($subSubForm, "subSubForm"); $this->form->addSubForm($subForm, "subForm"); $this->form->render(); $this->assertEquals("subForm[subSubForm]", $this->form->getSubForm("subForm")->getSubForm("subSubForm")->getElementsBelongTo()); }
public function testAddingSubFormResetsBelongsToWithDifferentSubFormName() { $subForm = new SubForm(); $subForm->setName('quo')->addElement('text', 'foo'); $this->form->addSubForm($subForm, 'bar'); $this->assertEquals('bar', $subForm->foo->getBelongsTo()); }