Browse Source

Move unlocked field resetting to end()

Doing the field reset in end() allows field to be unlocked before the
form is created.

Refs #8879
Mark Story 9 years ago
parent
commit
f2bc2a1728
2 changed files with 4 additions and 2 deletions
  1. 1 1
      src/View/Helper/FormHelper.php
  2. 3 1
      tests/TestCase/View/Helper/FormHelperTest.php

+ 1 - 1
src/View/Helper/FormHelper.php

@@ -420,7 +420,6 @@ class FormHelper extends Helper
         $htmlAttributes += $options;
 
         $this->fields = [];
-        $this->_unlockedFields = [];
         if ($this->requestType !== 'get') {
             $append .= $this->_csrfField();
         }
@@ -531,6 +530,7 @@ class FormHelper extends Helper
         ) {
             $out .= $this->secure($this->fields, $secureAttributes);
             $this->fields = [];
+            $this->_unlockedFields = [];
         }
         $out .= $this->formatTemplate('formEnd', []);
 

+ 3 - 1
tests/TestCase/View/Helper/FormHelperTest.php

@@ -2292,8 +2292,10 @@ class FormHelperTest extends TestCase
             'unlockedFields' => []
         ];
 
-        $this->Form->create('Contact');
         $this->Form->unlockField('Contact.id');
+        $this->Form->create('Contact');
+        $this->Form->hidden('Contact.id', ['value' => 1]);
+        $this->assertEmpty($this->Form->fields, 'Field should be unlocked');
         $this->Form->end();
 
         $this->Form->create('Contact');