0

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 :)

3
  • This gives me a error: The option "0" does not exist. Commented Nov 6, 2018 at 23:55
  • 1
    The CollectionType is typically expecting a collection of structured FormTypes, This is because the desired form elements to be included are defined in it, including those that are an entity. Your Data Model (class) should hold the array value. Have a look at How to Embed a Collection of Forms Commented Nov 7, 2018 at 0:40
  • yeah and better way is just i.e. post got tags, so normal is to create form post and form tag and if you wanna add tags in post it is better way to just add collection type of tags forms with entitystype which is inside tags form - and it works, correct ? Commented Nov 7, 2018 at 10:49

2 Answers 2

1

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

Sign up to request clarification or add additional context in comments.

1 Comment

yeah i did it, SearchProductsType, and i attach it to CollectionType in OrdersType and it works fine.
0

Just place your array( part inside the entry_options

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.