Creating a Choice Type field dynamically on Symfony 3How to create a custom SaveType which is child of SubmitType in Symfony formsSymfony : Create severals fields from EntityType, like Collection TypeSymfony 2 Form fields collectionSymfony form with EntityType field yields a 'This value should not be blank' error if the field has a Valid() contraint in the object classUsing @ParamConverter for a setter on Entity propertyAccess all fields of an EntityTypeSymfony 3 File upload and DB, if new file not uploaded old file field removedFetch values from 2 fields and show multiplication in third fieldGetting data from array with embed forms - Symfony 4Symfony 4 : Writing unit tests for a Form class that uses EntityType fields

Is it okay / does it make sense for another player to join a running game of Munchkin?

How do I rename a LINUX host without needing to reboot for the rename to take effect?

Opposite of a diet

Can somebody explain Brexit in a few child-proof sentences?

Where in the Bible does the greeting ("Dominus Vobiscum") used at Mass come from?

Hide Select Output from T-SQL

How does residential electricity work?

Can I Retrieve Email Addresses from BCC?

Is exact Kanji stroke length important?

How to be diplomatic in refusing to write code that breaches the privacy of our users

What is the intuitive meaning of having a linear relationship between the logs of two variables?

Increase performance creating Mandelbrot set in python

Greatest common substring

The plural of 'stomach"

Why Were Madagascar and New Zealand Discovered So Late?

Go Pregnant or Go Home

How does a character multiclassing into warlock get a focus?

What's the purpose of "true" in bash "if sudo true; then"

Your magic is very sketchy

Modify casing of marked letters

What's a natural way to say that someone works somewhere (for a job)?

Teaching indefinite integrals that require special-casing

What defines a dissertation?

HashMap containsKey() returns false although hashCode() and equals() are true



Creating a Choice Type field dynamically on Symfony 3


How to create a custom SaveType which is child of SubmitType in Symfony formsSymfony : Create severals fields from EntityType, like Collection TypeSymfony 2 Form fields collectionSymfony form with EntityType field yields a 'This value should not be blank' error if the field has a Valid() contraint in the object classUsing @ParamConverter for a setter on Entity propertyAccess all fields of an EntityTypeSymfony 3 File upload and DB, if new file not uploaded old file field removedFetch values from 2 fields and show multiplication in third fieldGetting data from array with embed forms - Symfony 4Symfony 4 : Writing unit tests for a Form class that uses EntityType fields













-1















Im quite new with Symfony and i'm looking for a way to dynamically create a choicetype field in a form.



In fact i have several product that i fetch with the query_builder in my form.
After presenting the product and the price, i want a select dropdown so the user can select the quantity of products to get.



In fact, in my builder form, i fetch the products thanks to the query builder, and get +/- 30 products, but this number can change.



The problem is that i want as many dropdowns as products, until now my builder looks like this :



 return $builder
->add('price', EntityType::class ,[
'class'=> Price::class,
'query_builder' => function (PriceRepository $pr) use ($goldenOptions, $currentCompany)
return $pr->getPrice($goldenOptions, $currentCompany->getOrder()->getCompanyType(), $currentCompany->getOnboardingRevenues(), true);
,
'expanded'=>true,
'multiple'=>true,
'placeholder'=>true
])
->add('quantity',ChoiceType::class,[
'choices'=>['mensuel'=>true,'trimestriel'=>false,'1'=>1,'2'=>2,'3'=>3,'4'=>4],
'expanded'=>false,
'multiple'=>false
])
->add('submit', SubmitType::class,[
'attr' => ['class' => 'save'],
'label'=>'Sauvegarder',
'attr' => ['class' => 'btn btn-purple btn-rounded']
])


problem is that this way i only get 1 dropdown, and i want several. I have managed to reproduced it with javascript but when i handle the request and getData from it, Symfony only recognise the first 'quantity' field.



If anyone as ideas on how can i created myultiples 'quantity' fields and symfony recognized them thanks. Maybe an event listener but i have no clue how i could actually do that.










share|improve this question


























    -1















    Im quite new with Symfony and i'm looking for a way to dynamically create a choicetype field in a form.



    In fact i have several product that i fetch with the query_builder in my form.
    After presenting the product and the price, i want a select dropdown so the user can select the quantity of products to get.



    In fact, in my builder form, i fetch the products thanks to the query builder, and get +/- 30 products, but this number can change.



    The problem is that i want as many dropdowns as products, until now my builder looks like this :



     return $builder
    ->add('price', EntityType::class ,[
    'class'=> Price::class,
    'query_builder' => function (PriceRepository $pr) use ($goldenOptions, $currentCompany)
    return $pr->getPrice($goldenOptions, $currentCompany->getOrder()->getCompanyType(), $currentCompany->getOnboardingRevenues(), true);
    ,
    'expanded'=>true,
    'multiple'=>true,
    'placeholder'=>true
    ])
    ->add('quantity',ChoiceType::class,[
    'choices'=>['mensuel'=>true,'trimestriel'=>false,'1'=>1,'2'=>2,'3'=>3,'4'=>4],
    'expanded'=>false,
    'multiple'=>false
    ])
    ->add('submit', SubmitType::class,[
    'attr' => ['class' => 'save'],
    'label'=>'Sauvegarder',
    'attr' => ['class' => 'btn btn-purple btn-rounded']
    ])


    problem is that this way i only get 1 dropdown, and i want several. I have managed to reproduced it with javascript but when i handle the request and getData from it, Symfony only recognise the first 'quantity' field.



    If anyone as ideas on how can i created myultiples 'quantity' fields and symfony recognized them thanks. Maybe an event listener but i have no clue how i could actually do that.










    share|improve this question
























      -1












      -1








      -1








      Im quite new with Symfony and i'm looking for a way to dynamically create a choicetype field in a form.



      In fact i have several product that i fetch with the query_builder in my form.
      After presenting the product and the price, i want a select dropdown so the user can select the quantity of products to get.



      In fact, in my builder form, i fetch the products thanks to the query builder, and get +/- 30 products, but this number can change.



      The problem is that i want as many dropdowns as products, until now my builder looks like this :



       return $builder
      ->add('price', EntityType::class ,[
      'class'=> Price::class,
      'query_builder' => function (PriceRepository $pr) use ($goldenOptions, $currentCompany)
      return $pr->getPrice($goldenOptions, $currentCompany->getOrder()->getCompanyType(), $currentCompany->getOnboardingRevenues(), true);
      ,
      'expanded'=>true,
      'multiple'=>true,
      'placeholder'=>true
      ])
      ->add('quantity',ChoiceType::class,[
      'choices'=>['mensuel'=>true,'trimestriel'=>false,'1'=>1,'2'=>2,'3'=>3,'4'=>4],
      'expanded'=>false,
      'multiple'=>false
      ])
      ->add('submit', SubmitType::class,[
      'attr' => ['class' => 'save'],
      'label'=>'Sauvegarder',
      'attr' => ['class' => 'btn btn-purple btn-rounded']
      ])


      problem is that this way i only get 1 dropdown, and i want several. I have managed to reproduced it with javascript but when i handle the request and getData from it, Symfony only recognise the first 'quantity' field.



      If anyone as ideas on how can i created myultiples 'quantity' fields and symfony recognized them thanks. Maybe an event listener but i have no clue how i could actually do that.










      share|improve this question














      Im quite new with Symfony and i'm looking for a way to dynamically create a choicetype field in a form.



      In fact i have several product that i fetch with the query_builder in my form.
      After presenting the product and the price, i want a select dropdown so the user can select the quantity of products to get.



      In fact, in my builder form, i fetch the products thanks to the query builder, and get +/- 30 products, but this number can change.



      The problem is that i want as many dropdowns as products, until now my builder looks like this :



       return $builder
      ->add('price', EntityType::class ,[
      'class'=> Price::class,
      'query_builder' => function (PriceRepository $pr) use ($goldenOptions, $currentCompany)
      return $pr->getPrice($goldenOptions, $currentCompany->getOrder()->getCompanyType(), $currentCompany->getOnboardingRevenues(), true);
      ,
      'expanded'=>true,
      'multiple'=>true,
      'placeholder'=>true
      ])
      ->add('quantity',ChoiceType::class,[
      'choices'=>['mensuel'=>true,'trimestriel'=>false,'1'=>1,'2'=>2,'3'=>3,'4'=>4],
      'expanded'=>false,
      'multiple'=>false
      ])
      ->add('submit', SubmitType::class,[
      'attr' => ['class' => 'save'],
      'label'=>'Sauvegarder',
      'attr' => ['class' => 'btn btn-purple btn-rounded']
      ])


      problem is that this way i only get 1 dropdown, and i want several. I have managed to reproduced it with javascript but when i handle the request and getData from it, Symfony only recognise the first 'quantity' field.



      If anyone as ideas on how can i created myultiples 'quantity' fields and symfony recognized them thanks. Maybe an event listener but i have no clue how i could actually do that.







      php symfony






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Mar 7 at 11:35









      Pedro4000Pedro4000

      1




      1






















          1 Answer
          1






          active

          oldest

          votes


















          0














          I'm guessing this is for some kind of e-commerce app where you have a cart with products and want to select quantity.



          I would have an entity for "Cart", that holds many "CartProduct" that each have one "Product" as a relationship and other attributes for quantity etc.



          With this you can have a CartForm that embeds any number of CartProductForm with quantity etc. for each one.



          Same as the example in the docs, where "Task" would be "Cart" and "Tags" would be "CartProducts":
          https://symfony.com/doc/current/form/form_collections.html






          share|improve this answer






















            Your Answer






            StackExchange.ifUsing("editor", function ()
            StackExchange.using("externalEditor", function ()
            StackExchange.using("snippets", function ()
            StackExchange.snippets.init();
            );
            );
            , "code-snippets");

            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "1"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader:
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            ,
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );













            draft saved

            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55042839%2fcreating-a-choice-type-field-dynamically-on-symfony-3%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            I'm guessing this is for some kind of e-commerce app where you have a cart with products and want to select quantity.



            I would have an entity for "Cart", that holds many "CartProduct" that each have one "Product" as a relationship and other attributes for quantity etc.



            With this you can have a CartForm that embeds any number of CartProductForm with quantity etc. for each one.



            Same as the example in the docs, where "Task" would be "Cart" and "Tags" would be "CartProducts":
            https://symfony.com/doc/current/form/form_collections.html






            share|improve this answer



























              0














              I'm guessing this is for some kind of e-commerce app where you have a cart with products and want to select quantity.



              I would have an entity for "Cart", that holds many "CartProduct" that each have one "Product" as a relationship and other attributes for quantity etc.



              With this you can have a CartForm that embeds any number of CartProductForm with quantity etc. for each one.



              Same as the example in the docs, where "Task" would be "Cart" and "Tags" would be "CartProducts":
              https://symfony.com/doc/current/form/form_collections.html






              share|improve this answer

























                0












                0








                0







                I'm guessing this is for some kind of e-commerce app where you have a cart with products and want to select quantity.



                I would have an entity for "Cart", that holds many "CartProduct" that each have one "Product" as a relationship and other attributes for quantity etc.



                With this you can have a CartForm that embeds any number of CartProductForm with quantity etc. for each one.



                Same as the example in the docs, where "Task" would be "Cart" and "Tags" would be "CartProducts":
                https://symfony.com/doc/current/form/form_collections.html






                share|improve this answer













                I'm guessing this is for some kind of e-commerce app where you have a cart with products and want to select quantity.



                I would have an entity for "Cart", that holds many "CartProduct" that each have one "Product" as a relationship and other attributes for quantity etc.



                With this you can have a CartForm that embeds any number of CartProductForm with quantity etc. for each one.



                Same as the example in the docs, where "Task" would be "Cart" and "Tags" would be "CartProducts":
                https://symfony.com/doc/current/form/form_collections.html







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Mar 7 at 12:25









                Sondre EdvardsenSondre Edvardsen

                1312




                1312





























                    draft saved

                    draft discarded
















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid


                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.

                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55042839%2fcreating-a-choice-type-field-dynamically-on-symfony-3%23new-answer', 'question_page');

                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    AWS Lex not identifying response if by a variable The 2019 Stack Overflow Developer Survey Results Are In Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern) The Ask Question Wizard is Live! Data science time! April 2019 and salary with experienceEnforcing custom enumeration in AWS LEX for slot valuesHow to give response based on user response in Amazon Lex?Intercepting AWS Lambda Response to a AWS Lex QueryLex chat bot error: Reached second execution of fulfillment lambda on the same utteranceamazon lex showing invalid responseLambda response send back to Lex slot?Response card in Amazon lexAmazon Lex - Lambda response return HTML to botHow can I solve 424 (Failed Dependency) (python) obtained from Amazon lex?

                    Алба-Юлія

                    Захаров Федір Захарович