How to add radio option in Magento 2?magento2: how place 2-3 form fields in one row in admin edit formData...

How to copy the rest of lines of a file to another file

How do you make a gun that shoots melee weapons and/or swords?

Has a sovereign Communist government ever run, and conceded loss, on a fair election?

Does an unused member variable take up memory?

Why do phishing e-mails use faked e-mail addresses instead of the real one?

Is there a way to make cleveref distinguish two environments with the same counter?

Why is there an extra space when I type "ls" on the Desktop?

Why does Central Limit Theorem break down in my simulation?

Create chunks from an array

What would be the most expensive material to an intergalactic society?

How can a demon take control of a human body during REM sleep?

"If + would" conditional in present perfect tense

How do I increase the number of TTY consoles?

Is this Paypal Github SDK reference really a dangerous site?

Which country has more?

What do you call someone who likes to pick fights?

Are these two graphs isomorphic? Why/Why not?

How exactly does an Ethernet collision happen in the cable, since nodes use different circuits for Tx and Rx?

How to educate team mate to take screenshots for bugs with out unwanted stuff

Having the player face themselves after the mid-game

What is better: yes / no radio, or simple checkbox?

Rationale to prefer local variables over instance variables?

Movie: boy escapes the real world and goes to a fantasy world with big furry trolls

(Codewars) Linked Lists-Sorted Insert



How to add radio option in Magento 2?


magento2: how place 2-3 form fields in one row in admin edit formData population in UI formAdd to cart issue - Magento 2.1Magento 2 add Sort By Best Sellers Option on category products litsing pageMagento 2 : Dropdown Option not Showing in Admin FormMagento 2 Add new field to Magento_User admin formHow to clear a custom option via REST product updateAdmin setting js minify option is not workingAdd attribute name to configurable select option in Magento2?How do you add custom styling to radio buttons in the shipping method section of Magento 2 checkout?How to Update Magento 2 configurable child products price by REST API













5















I am trying to add radio option but showing single radio without any label



$fieldset->addField(
'test',
'radio',
[
'label' => __('test'),
'title' => __('test'),
'name' => 'test',
'required' => true,
'values' => array(
array('value'=>'1','label'=>'Radio1'),
array('value'=>'2','label'=>'Radio2'),
array('value'=>'3','label'=>'Radio3'),
),
'disabled' => $isDisabled
]
);









share|improve this question





























    5















    I am trying to add radio option but showing single radio without any label



    $fieldset->addField(
    'test',
    'radio',
    [
    'label' => __('test'),
    'title' => __('test'),
    'name' => 'test',
    'required' => true,
    'values' => array(
    array('value'=>'1','label'=>'Radio1'),
    array('value'=>'2','label'=>'Radio2'),
    array('value'=>'3','label'=>'Radio3'),
    ),
    'disabled' => $isDisabled
    ]
    );









    share|improve this question



























      5












      5








      5








      I am trying to add radio option but showing single radio without any label



      $fieldset->addField(
      'test',
      'radio',
      [
      'label' => __('test'),
      'title' => __('test'),
      'name' => 'test',
      'required' => true,
      'values' => array(
      array('value'=>'1','label'=>'Radio1'),
      array('value'=>'2','label'=>'Radio2'),
      array('value'=>'3','label'=>'Radio3'),
      ),
      'disabled' => $isDisabled
      ]
      );









      share|improve this question
















      I am trying to add radio option but showing single radio without any label



      $fieldset->addField(
      'test',
      'radio',
      [
      'label' => __('test'),
      'title' => __('test'),
      'name' => 'test',
      'required' => true,
      'values' => array(
      array('value'=>'1','label'=>'Radio1'),
      array('value'=>'2','label'=>'Radio2'),
      array('value'=>'3','label'=>'Radio3'),
      ),
      'disabled' => $isDisabled
      ]
      );






      magento2 magento-2.0 adminform






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited 2 mins ago









      magefms

      1,254220




      1,254220










      asked May 4 '16 at 10:34









      Qaisar SattiQaisar Satti

      26.8k1256109




      26.8k1256109






















          3 Answers
          3






          active

          oldest

          votes


















          5














          change type from radio to radios



          $fieldset->addField(
          'test',
          'radios',
          [
          'label' => __('test'),
          'title' => __('test'),
          'name' => 'test',
          'required' => true,
          'values' => array(
          array('value'=>'1','label'=>'Radio1'),
          array('value'=>'2','label'=>'Radio2'),
          array('value'=>'3','label'=>'Radio3'),
          ),
          'disabled' => $isDisabled
          ]
          );


          for more types you can look in to namespace MagentoFrameworkDataFormElement






          share|improve this answer































            2














            Use below code:



            $fieldset->addField(
            'test',
            'radios',
            [
            'name' => 'test',
            'label' => __('Radio'),
            'title' => __('Radio'),
            'required' => true,
            'values' => [
            ['value' =>1, 'label' => __('Yes')],
            ['value' => 0, 'label' => __('No')]
            ],
            'disabled' => $isElementDisabled
            ]
            );


            enter image description here






            share|improve this answer
























            • could you guide me to get all radios in single row as all my radios are taking 1 row each

              – Mohammad Mujassam
              May 4 '16 at 11:09













            • Use above code which i have added in answer

              – Prashant Valanda
              May 4 '16 at 11:10











            • It will display only two option in one row if options are more than 2 it will not display in single row

              – Prashant Valanda
              May 4 '16 at 11:15











            • @PrashantValanda you code is not matching with your output image

              – Qaisar Satti
              May 4 '16 at 11:16











            • It is same as image only label is changed because while i capturing snap at that time label is other. :)

              – Prashant Valanda
              May 4 '16 at 11:16



















            2














            It seems like the way Magento 2 handles radio require multiple radio fields with the same name.



            There's a good example in app/code/Magento/ConfigurableProduct/Block/Adminhtml/Product/Edit/AttributeSet/Form.php



            In your case the right code would be:



                $fieldset->addField(
            'Radio1',
            'radio',
            [
            'name' => 'test',
            'value' => '1'
            ]
            );
            $fieldset->addField(
            'Radio2',
            'radio',
            [
            'name' => 'test',
            'value' => '2'
            ]
            );
            $fieldset->addField(
            'Radio3',
            'radio',
            [
            'name' => 'test',
            'value' => '3'
            ]
            );


            On top of that it seems like app/code/Magento/Catalog/Block/Adminhtml/Product/Helper/Form/Weight.php uses a slightly different method in the below code but as it is a custom element I'm not sure if that will fit your needs:



                $this->weightSwitcher = $factoryElement->create('radios');
            $this->weightSwitcher->setValue(
            WeightResolver::HAS_WEIGHT
            )->setValues(
            [
            ['value' => WeightResolver::HAS_WEIGHT, 'label' => __('Yes')],
            ['value' => WeightResolver::HAS_NO_WEIGHT, 'label' => __('No')]
            ]
            )->setId(
            'weight-switcher'
            )->setName(
            'product_has_weight'
            )->setLabel(
            __('Does this have a weight?')
            );





            share|improve this answer























              Your Answer








              StackExchange.ready(function() {
              var channelOptions = {
              tags: "".split(" "),
              id: "479"
              };
              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: false,
              noModals: true,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: null,
              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%2fmagento.stackexchange.com%2fquestions%2f113902%2fhow-to-add-radio-option-in-magento-2%23new-answer', 'question_page');
              }
              );

              Post as a guest















              Required, but never shown

























              3 Answers
              3






              active

              oldest

              votes








              3 Answers
              3






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes









              5














              change type from radio to radios



              $fieldset->addField(
              'test',
              'radios',
              [
              'label' => __('test'),
              'title' => __('test'),
              'name' => 'test',
              'required' => true,
              'values' => array(
              array('value'=>'1','label'=>'Radio1'),
              array('value'=>'2','label'=>'Radio2'),
              array('value'=>'3','label'=>'Radio3'),
              ),
              'disabled' => $isDisabled
              ]
              );


              for more types you can look in to namespace MagentoFrameworkDataFormElement






              share|improve this answer




























                5














                change type from radio to radios



                $fieldset->addField(
                'test',
                'radios',
                [
                'label' => __('test'),
                'title' => __('test'),
                'name' => 'test',
                'required' => true,
                'values' => array(
                array('value'=>'1','label'=>'Radio1'),
                array('value'=>'2','label'=>'Radio2'),
                array('value'=>'3','label'=>'Radio3'),
                ),
                'disabled' => $isDisabled
                ]
                );


                for more types you can look in to namespace MagentoFrameworkDataFormElement






                share|improve this answer


























                  5












                  5








                  5







                  change type from radio to radios



                  $fieldset->addField(
                  'test',
                  'radios',
                  [
                  'label' => __('test'),
                  'title' => __('test'),
                  'name' => 'test',
                  'required' => true,
                  'values' => array(
                  array('value'=>'1','label'=>'Radio1'),
                  array('value'=>'2','label'=>'Radio2'),
                  array('value'=>'3','label'=>'Radio3'),
                  ),
                  'disabled' => $isDisabled
                  ]
                  );


                  for more types you can look in to namespace MagentoFrameworkDataFormElement






                  share|improve this answer













                  change type from radio to radios



                  $fieldset->addField(
                  'test',
                  'radios',
                  [
                  'label' => __('test'),
                  'title' => __('test'),
                  'name' => 'test',
                  'required' => true,
                  'values' => array(
                  array('value'=>'1','label'=>'Radio1'),
                  array('value'=>'2','label'=>'Radio2'),
                  array('value'=>'3','label'=>'Radio3'),
                  ),
                  'disabled' => $isDisabled
                  ]
                  );


                  for more types you can look in to namespace MagentoFrameworkDataFormElement







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered May 4 '16 at 10:55









                  R TR T

                  93711225




                  93711225

























                      2














                      Use below code:



                      $fieldset->addField(
                      'test',
                      'radios',
                      [
                      'name' => 'test',
                      'label' => __('Radio'),
                      'title' => __('Radio'),
                      'required' => true,
                      'values' => [
                      ['value' =>1, 'label' => __('Yes')],
                      ['value' => 0, 'label' => __('No')]
                      ],
                      'disabled' => $isElementDisabled
                      ]
                      );


                      enter image description here






                      share|improve this answer
























                      • could you guide me to get all radios in single row as all my radios are taking 1 row each

                        – Mohammad Mujassam
                        May 4 '16 at 11:09













                      • Use above code which i have added in answer

                        – Prashant Valanda
                        May 4 '16 at 11:10











                      • It will display only two option in one row if options are more than 2 it will not display in single row

                        – Prashant Valanda
                        May 4 '16 at 11:15











                      • @PrashantValanda you code is not matching with your output image

                        – Qaisar Satti
                        May 4 '16 at 11:16











                      • It is same as image only label is changed because while i capturing snap at that time label is other. :)

                        – Prashant Valanda
                        May 4 '16 at 11:16
















                      2














                      Use below code:



                      $fieldset->addField(
                      'test',
                      'radios',
                      [
                      'name' => 'test',
                      'label' => __('Radio'),
                      'title' => __('Radio'),
                      'required' => true,
                      'values' => [
                      ['value' =>1, 'label' => __('Yes')],
                      ['value' => 0, 'label' => __('No')]
                      ],
                      'disabled' => $isElementDisabled
                      ]
                      );


                      enter image description here






                      share|improve this answer
























                      • could you guide me to get all radios in single row as all my radios are taking 1 row each

                        – Mohammad Mujassam
                        May 4 '16 at 11:09













                      • Use above code which i have added in answer

                        – Prashant Valanda
                        May 4 '16 at 11:10











                      • It will display only two option in one row if options are more than 2 it will not display in single row

                        – Prashant Valanda
                        May 4 '16 at 11:15











                      • @PrashantValanda you code is not matching with your output image

                        – Qaisar Satti
                        May 4 '16 at 11:16











                      • It is same as image only label is changed because while i capturing snap at that time label is other. :)

                        – Prashant Valanda
                        May 4 '16 at 11:16














                      2












                      2








                      2







                      Use below code:



                      $fieldset->addField(
                      'test',
                      'radios',
                      [
                      'name' => 'test',
                      'label' => __('Radio'),
                      'title' => __('Radio'),
                      'required' => true,
                      'values' => [
                      ['value' =>1, 'label' => __('Yes')],
                      ['value' => 0, 'label' => __('No')]
                      ],
                      'disabled' => $isElementDisabled
                      ]
                      );


                      enter image description here






                      share|improve this answer













                      Use below code:



                      $fieldset->addField(
                      'test',
                      'radios',
                      [
                      'name' => 'test',
                      'label' => __('Radio'),
                      'title' => __('Radio'),
                      'required' => true,
                      'values' => [
                      ['value' =>1, 'label' => __('Yes')],
                      ['value' => 0, 'label' => __('No')]
                      ],
                      'disabled' => $isElementDisabled
                      ]
                      );


                      enter image description here







                      share|improve this answer












                      share|improve this answer



                      share|improve this answer










                      answered May 4 '16 at 10:51









                      Prashant ValandaPrashant Valanda

                      9,80712355




                      9,80712355













                      • could you guide me to get all radios in single row as all my radios are taking 1 row each

                        – Mohammad Mujassam
                        May 4 '16 at 11:09













                      • Use above code which i have added in answer

                        – Prashant Valanda
                        May 4 '16 at 11:10











                      • It will display only two option in one row if options are more than 2 it will not display in single row

                        – Prashant Valanda
                        May 4 '16 at 11:15











                      • @PrashantValanda you code is not matching with your output image

                        – Qaisar Satti
                        May 4 '16 at 11:16











                      • It is same as image only label is changed because while i capturing snap at that time label is other. :)

                        – Prashant Valanda
                        May 4 '16 at 11:16



















                      • could you guide me to get all radios in single row as all my radios are taking 1 row each

                        – Mohammad Mujassam
                        May 4 '16 at 11:09













                      • Use above code which i have added in answer

                        – Prashant Valanda
                        May 4 '16 at 11:10











                      • It will display only two option in one row if options are more than 2 it will not display in single row

                        – Prashant Valanda
                        May 4 '16 at 11:15











                      • @PrashantValanda you code is not matching with your output image

                        – Qaisar Satti
                        May 4 '16 at 11:16











                      • It is same as image only label is changed because while i capturing snap at that time label is other. :)

                        – Prashant Valanda
                        May 4 '16 at 11:16

















                      could you guide me to get all radios in single row as all my radios are taking 1 row each

                      – Mohammad Mujassam
                      May 4 '16 at 11:09







                      could you guide me to get all radios in single row as all my radios are taking 1 row each

                      – Mohammad Mujassam
                      May 4 '16 at 11:09















                      Use above code which i have added in answer

                      – Prashant Valanda
                      May 4 '16 at 11:10





                      Use above code which i have added in answer

                      – Prashant Valanda
                      May 4 '16 at 11:10













                      It will display only two option in one row if options are more than 2 it will not display in single row

                      – Prashant Valanda
                      May 4 '16 at 11:15





                      It will display only two option in one row if options are more than 2 it will not display in single row

                      – Prashant Valanda
                      May 4 '16 at 11:15













                      @PrashantValanda you code is not matching with your output image

                      – Qaisar Satti
                      May 4 '16 at 11:16





                      @PrashantValanda you code is not matching with your output image

                      – Qaisar Satti
                      May 4 '16 at 11:16













                      It is same as image only label is changed because while i capturing snap at that time label is other. :)

                      – Prashant Valanda
                      May 4 '16 at 11:16





                      It is same as image only label is changed because while i capturing snap at that time label is other. :)

                      – Prashant Valanda
                      May 4 '16 at 11:16











                      2














                      It seems like the way Magento 2 handles radio require multiple radio fields with the same name.



                      There's a good example in app/code/Magento/ConfigurableProduct/Block/Adminhtml/Product/Edit/AttributeSet/Form.php



                      In your case the right code would be:



                          $fieldset->addField(
                      'Radio1',
                      'radio',
                      [
                      'name' => 'test',
                      'value' => '1'
                      ]
                      );
                      $fieldset->addField(
                      'Radio2',
                      'radio',
                      [
                      'name' => 'test',
                      'value' => '2'
                      ]
                      );
                      $fieldset->addField(
                      'Radio3',
                      'radio',
                      [
                      'name' => 'test',
                      'value' => '3'
                      ]
                      );


                      On top of that it seems like app/code/Magento/Catalog/Block/Adminhtml/Product/Helper/Form/Weight.php uses a slightly different method in the below code but as it is a custom element I'm not sure if that will fit your needs:



                          $this->weightSwitcher = $factoryElement->create('radios');
                      $this->weightSwitcher->setValue(
                      WeightResolver::HAS_WEIGHT
                      )->setValues(
                      [
                      ['value' => WeightResolver::HAS_WEIGHT, 'label' => __('Yes')],
                      ['value' => WeightResolver::HAS_NO_WEIGHT, 'label' => __('No')]
                      ]
                      )->setId(
                      'weight-switcher'
                      )->setName(
                      'product_has_weight'
                      )->setLabel(
                      __('Does this have a weight?')
                      );





                      share|improve this answer




























                        2














                        It seems like the way Magento 2 handles radio require multiple radio fields with the same name.



                        There's a good example in app/code/Magento/ConfigurableProduct/Block/Adminhtml/Product/Edit/AttributeSet/Form.php



                        In your case the right code would be:



                            $fieldset->addField(
                        'Radio1',
                        'radio',
                        [
                        'name' => 'test',
                        'value' => '1'
                        ]
                        );
                        $fieldset->addField(
                        'Radio2',
                        'radio',
                        [
                        'name' => 'test',
                        'value' => '2'
                        ]
                        );
                        $fieldset->addField(
                        'Radio3',
                        'radio',
                        [
                        'name' => 'test',
                        'value' => '3'
                        ]
                        );


                        On top of that it seems like app/code/Magento/Catalog/Block/Adminhtml/Product/Helper/Form/Weight.php uses a slightly different method in the below code but as it is a custom element I'm not sure if that will fit your needs:



                            $this->weightSwitcher = $factoryElement->create('radios');
                        $this->weightSwitcher->setValue(
                        WeightResolver::HAS_WEIGHT
                        )->setValues(
                        [
                        ['value' => WeightResolver::HAS_WEIGHT, 'label' => __('Yes')],
                        ['value' => WeightResolver::HAS_NO_WEIGHT, 'label' => __('No')]
                        ]
                        )->setId(
                        'weight-switcher'
                        )->setName(
                        'product_has_weight'
                        )->setLabel(
                        __('Does this have a weight?')
                        );





                        share|improve this answer


























                          2












                          2








                          2







                          It seems like the way Magento 2 handles radio require multiple radio fields with the same name.



                          There's a good example in app/code/Magento/ConfigurableProduct/Block/Adminhtml/Product/Edit/AttributeSet/Form.php



                          In your case the right code would be:



                              $fieldset->addField(
                          'Radio1',
                          'radio',
                          [
                          'name' => 'test',
                          'value' => '1'
                          ]
                          );
                          $fieldset->addField(
                          'Radio2',
                          'radio',
                          [
                          'name' => 'test',
                          'value' => '2'
                          ]
                          );
                          $fieldset->addField(
                          'Radio3',
                          'radio',
                          [
                          'name' => 'test',
                          'value' => '3'
                          ]
                          );


                          On top of that it seems like app/code/Magento/Catalog/Block/Adminhtml/Product/Helper/Form/Weight.php uses a slightly different method in the below code but as it is a custom element I'm not sure if that will fit your needs:



                              $this->weightSwitcher = $factoryElement->create('radios');
                          $this->weightSwitcher->setValue(
                          WeightResolver::HAS_WEIGHT
                          )->setValues(
                          [
                          ['value' => WeightResolver::HAS_WEIGHT, 'label' => __('Yes')],
                          ['value' => WeightResolver::HAS_NO_WEIGHT, 'label' => __('No')]
                          ]
                          )->setId(
                          'weight-switcher'
                          )->setName(
                          'product_has_weight'
                          )->setLabel(
                          __('Does this have a weight?')
                          );





                          share|improve this answer













                          It seems like the way Magento 2 handles radio require multiple radio fields with the same name.



                          There's a good example in app/code/Magento/ConfigurableProduct/Block/Adminhtml/Product/Edit/AttributeSet/Form.php



                          In your case the right code would be:



                              $fieldset->addField(
                          'Radio1',
                          'radio',
                          [
                          'name' => 'test',
                          'value' => '1'
                          ]
                          );
                          $fieldset->addField(
                          'Radio2',
                          'radio',
                          [
                          'name' => 'test',
                          'value' => '2'
                          ]
                          );
                          $fieldset->addField(
                          'Radio3',
                          'radio',
                          [
                          'name' => 'test',
                          'value' => '3'
                          ]
                          );


                          On top of that it seems like app/code/Magento/Catalog/Block/Adminhtml/Product/Helper/Form/Weight.php uses a slightly different method in the below code but as it is a custom element I'm not sure if that will fit your needs:



                              $this->weightSwitcher = $factoryElement->create('radios');
                          $this->weightSwitcher->setValue(
                          WeightResolver::HAS_WEIGHT
                          )->setValues(
                          [
                          ['value' => WeightResolver::HAS_WEIGHT, 'label' => __('Yes')],
                          ['value' => WeightResolver::HAS_NO_WEIGHT, 'label' => __('No')]
                          ]
                          )->setId(
                          'weight-switcher'
                          )->setName(
                          'product_has_weight'
                          )->setLabel(
                          __('Does this have a weight?')
                          );






                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered May 4 '16 at 10:52









                          Raphael at Digital PianismRaphael at Digital Pianism

                          54.6k22119277




                          54.6k22119277






























                              draft saved

                              draft discarded




















































                              Thanks for contributing an answer to Magento Stack Exchange!


                              • 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%2fmagento.stackexchange.com%2fquestions%2f113902%2fhow-to-add-radio-option-in-magento-2%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

                              “%fieldName is a required field.”, in Magento2 REST API Call for GET Method Type The Next...

                              How to change City field to a dropdown in Checkout step Magento 2Magento 2 : How to change UI field(s)...

                              夢乃愛華...