コード例 #1
0
ファイル: DojoTest.php プロジェクト: rafalwrzeszcz/zf2
 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;
 }
コード例 #2
0
 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;
 }
コード例 #3
0
    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());
    }
コード例 #4
0
ファイル: SubForm.php プロジェクト: heiglandreas/zf2
 /**
  * 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;
 }
コード例 #5
0
ファイル: SubForm.php プロジェクト: RomanShumkov/zf2
 /**
  * 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;
 }
コード例 #6
0
ファイル: FileTest.php プロジェクト: alab1001101/zf2
 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);
 }
コード例 #7
0
 /**
  * @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);
 }
コード例 #8
0
ファイル: FormTest.php プロジェクト: rafalwrzeszcz/zf2
 /**
  * @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');
 }
コード例 #9
0
ファイル: FormTest.php プロジェクト: rafalwrzeszcz/zf2
 /**
  * @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));
 }
コード例 #10
0
ファイル: FieldsetTest.php プロジェクト: niallmccrudden/zf2
 /**
  * @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);
 }
コード例 #11
0
 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());
 }
コード例 #12
0
ファイル: FormTest.php プロジェクト: rexmac/zf2
 public function testAddingSubFormResetsBelongsToWithDifferentSubFormName()
 {
     $subForm = new SubForm();
     $subForm->setName('quo')->addElement('text', 'foo');
     $this->form->addSubForm($subForm, 'bar');
     $this->assertEquals('bar', $subForm->foo->getBelongsTo());
 }