Sfoglia il codice sorgente

set required=false for delete checkbox

Thomas 14 anni fa
parent
commit
ca5f798a4d
2 ha cambiato i file con 9 aggiunte e 10 eliminazioni
  1. 6 9
      Form/EditableCollectionField.php
  2. 3 1
      Form/EditableFieldGroup.php

+ 6 - 9
Form/EditableCollectionField.php

@@ -41,11 +41,6 @@ class EditableCollectionField extends Form
      */
     public function __construct(FieldInterface $innerField, array $options = array())
     {
-
-        $innerField->add(new CheckboxField('_delete', array(
-            'required' => false
-        )));
-
         $this->prototype = $innerField;
 
         parent::__construct($innerField->getKey(), $options);
@@ -67,9 +62,10 @@ class EditableCollectionField extends Form
             }
         }
 
+        // add new element (+ icon)
         foreach ($taintedData as $name => $value) {
             if (!isset($this[$name])) {
-                $this->add($this->newField($name, $name));
+                $this->addField($name, $name);
             }
         }
 
@@ -99,13 +95,13 @@ class EditableCollectionField extends Form
     protected function newField($key, $propertyPath)
     {
         $field = clone $this->prototype;
+    
         $field->setKey($key);
         $field->setPropertyPath(null === $propertyPath ? null : '['.$propertyPath.']');
         
         return $field;
     }
 
-
     public function setData($collection)
     {
         if (!is_array($collection) && !$collection instanceof \Traversable) {
@@ -119,9 +115,10 @@ class EditableCollectionField extends Form
         parent::setData($collection);
     }
 
-    protected function updateObject(&$objectOrArray)
+    protected function writeObject(&$objectOrArray)
     {
-        parent::updateObject($objectOrArray);
+
+        parent::writeObject($objectOrArray);
 
         foreach ($this->removedFields as $name) {
             unset($objectOrArray[$name]);

+ 3 - 1
Form/EditableFieldGroup.php

@@ -29,7 +29,9 @@ class EditableFieldGroup extends Form
     public function __construct($key, array $options = array())
     {
 
-        $this->add(new CheckboxField('_delete'));
+        $this->add(new CheckboxField('_delete', array(
+            'required' => false
+        )));
 
         parent::__construct($key, $options);
     }