Explorar o código

ZF-7308: Auto-generate a form ID if none provided

- Fixes issues in dijit elements dependent on parent form

git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@23932 44c647ce-9c0f-0410-b52a-842ac1e357ba
matthew %!s(int64=14) %!d(string=hai) anos
pai
achega
853d629e8e

+ 5 - 0
library/Zend/Dojo/Form/Decorator/DijitForm.php

@@ -56,6 +56,11 @@ class Zend_Dojo_Form_Decorator_DijitForm extends Zend_Dojo_Form_Decorator_DijitC
         $dijitParams = $this->getDijitParams();
         $attribs     = array_merge($this->getAttribs(), $this->getOptions());
 
+        // Enforce id attribute of form for dojo events
+        if (!isset($attribs['name']) || !$attribs['name']) {
+            $element->setName(get_class($element) . '_' . uniqid());
+        }
+
         return $view->form($element->getName(), $attribs, $content);
     }
 }

+ 20 - 1
tests/Zend/Dojo/Form/Decorator/DijitFormTest.php

@@ -75,7 +75,7 @@ class Zend_Dojo_Form_Decorator_DijitFormTest extends PHPUnit_Framework_TestCase
         Zend_Registry::_unsetInstance();
         Zend_Dojo_View_Helper_Dojo::setUseDeclarative();
 
-        $this->view   = $this->getView();
+        $this->view      = $this->getView();
         $this->decorator = new Zend_Dojo_Form_Decorator_DijitForm();
         $this->element   = $this->getElement();
         $this->element->setView($this->view);
@@ -126,6 +126,25 @@ class Zend_Dojo_Form_Decorator_DijitFormTest extends PHPUnit_Framework_TestCase
         $html = $this->decorator->render('');
         $this->assertContains('dojoType="dijit.form.Form"', $html);
     }
+
+    public function testRenderingShouldEnforceFormName()
+    {
+        $element = new Zend_Dojo_Form();
+        $element->setAttribs(array(
+            'style'  => 'width: 300px; height: 500px;',
+            'class'  => 'someclass',
+            'dijitParams' => array(
+                'labelAttr' => 'foobar',
+                'typeAttr'  => 'barbaz',
+            ),
+        ));
+        $element->setView($this->view);
+        $decorator = new Zend_Dojo_Form_Decorator_DijitForm();
+        $decorator->setElement($element);
+
+        $html = $decorator->render('');
+        $this->assertRegexp('/id=".{1,}"/', $html, $html);
+    }
 }
 
 // Call Zend_Dojo_Form_Decorator_DijitFormTest::main() if this source file is executed directly.