flow
flow

Reputation: 137

CollectionType of EntityType Symfony Forms

It is even possible to make ?

->add('product', CollectionType::class, [
      'entry_type'    => EntityType::class, array(
        'data' => $options['product'],
        'placeholder' => 'Wybierz klienta',
        'multiple' => true,
        'class' => Products::class,
        'attr' => ['class' => 'chosen-select','data-placeholder'=>'Wybierz produkt'],
        'choice_label' => function ($product) {
            return  ''.$product->getJson()["products"]["name"] .' | Stan Magazynowy: '.$product->getJson()["products"]["stock"].'';
          },
      'label' => 'Wybierz produkty'

      ),
      'entry_options' => [
          'label' => 'Value',
      ],
      'label'        => 'Add, move, remove values and press Submit.',
      'allow_add'    => true,
      'allow_delete' => true,
      'prototype'    => true,
      'required'     => false,
      'attr'         => [
          'class' => 'my-selector',
      ],
  ])

I'll try to add chosen list of Products::class in CollectiontType, if some one wanna add product to new order, can add new EntityType and select product, and after submit i`ll handle this as array and save it to order.

If someone has another idea how to add products to form with quantity and then post it to array, please free to write :)

Upvotes: 0

Views: 3406

Answers (2)

ScorpioT1000
ScorpioT1000

Reputation: 358

Just place your array( part inside the entry_options

Upvotes: 0

JessGabriel
JessGabriel

Reputation: 1072

I think this is not the best way to do that. You just have to add CollectionType to the FormType and update you ProductType class to handle if this is selected or not. May be you have to create a custom formtype for products for order only :-/ . All hard work are on the javascript side

Upvotes: 1

Related Questions