[TYPO3-mvc] T3 6.2: Checkbox Viewhelper and n:m Relation - Wrong field name

g4-lisz at tonarchiv.ch g4-lisz at tonarchiv.ch
Fri Nov 14 12:20:37 CET 2014


Hi Jonas,

I couldn't find a neat solution yet...

I'm doing it now without "property" argument, but by naming the form
fields by myself, like:

<f:form.checkbox name="categoryArray[{category.uid}]" value="true"
       checked="{h:hasCategory(shop:shop, category:category)} />

As you can see I still need an array and also a custom viewhelper for
setting the flags properly.

BR,
Till

On 11/13/2014 02:14 PM, Jonas Eberle wrote:
> I am at the same point right now (managing sets of attributes that can
> be switched on or off in an n:m-property with Fluid forms).
>
> Did you find an elegant solution?
>
> Regards,
> Jonas
>
> Am 09.09.2014 um 06:30 schrieb g4-lisz at tonarchiv.ch:
>> I wonder how checkbox viewhelper should be used for n:m properties of an
>> object.
>>
>> Let's say we have an object Shop with property Category which is n:m
>> related, i.e. each shop may have one or more categories.
>>
>> In T3 i used an array for this type of property, which was mapped and
>> added to a object storage in the setter method (and vice versa in
>> getter):
>>
>>      /**
>>       * Set the categoryArray
>>       *
>>       * @param array $categoryArray
>>       * @return void
>>       */
>>      public function setCategoryArray($categoryArray) {
>>          $categoryRepository =
>> t3lib_div::makeInstance('Tx_Myext_Domain_Repository_CategoryRepository');
>>
>>                  $this->categories = new
>> Tx_Extbase_Persistence_ObjectStorage;
>>                      foreach($categoryArray as $category_id){
>>              $category = $categoryRepository->findByUid($category_id);
>>              $this->addCategory($category);
>>          }
>>      }
>>
>> This was ugly, but it was the only way to have the checkboxes checked
>> correctly by the viewhelper:
>>
>>                <f:for each="{categories}" as="category">
>>                    <div class="innerRow">
>>                        <label>
>>                            <f:form.checkbox property="categoryArray"
>> value="{category.uid}"/>
>>                            {category.name}
>>                        </label>
>>                    </div>
>>                </f:for>
>>
>> I.e. the appropriate checkboxes are checked when the form is loaded.
>>
>> With the new property mapper i get a problem: The checkbox viewhelper
>> renders the Category property as a string and not as an array:
>> ...
>>    <input type="checkbox" value="1"
>> name="tx_myext_fe_shopedit[shop][categories]">Cat
>> 1
>> ...
>>    <input type="checkbox" value="2"
>> name="tx_myext_fe_shopedit[shop][categories]">Cat
>> 2
>>
>> I get the error: #1297759968: Exception while property mapping at
>> property path "categoryArray":No converter found which can be used to
>> convert from "string" to "array"
>>
>> So what is the right way to do this?
>> Why does the viewhelper not render the property as an array?
>>     i.e.
>> <input type="checkbox" value="1"
>> name="tx_myext_fe_shopedit[shop][categories][]">Cat
>> 1 (like with T4.6)
>>
>> Cheers,
>> Till
>>
>> _______________________________________________
>> TYPO3-project-typo3v4mvc mailing list
>> TYPO3-project-typo3v4mvc at lists.typo3.org
>> http://lists.typo3.org/cgi-bin/mailman/listinfo/typo3-project-typo3v4mvc
>
>



More information about the TYPO3-project-typo3v4mvc mailing list