How to add radio option in Magento 2?
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
add a comment |
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
add a comment |
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
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
magento2 magento-2.0 adminform
edited 9 mins ago
magefms
1,254220
1,254220
asked May 4 '16 at 10:34
Qaisar SattiQaisar Satti
26.8k1256109
26.8k1256109
add a comment |
add a comment |
3 Answers
3
active
oldest
votes
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
add a comment |
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
]
);
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
|
show 5 more comments
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?')
);
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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
add a comment |
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
add a comment |
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
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
answered May 4 '16 at 10:55
R TR T
93711225
93711225
add a comment |
add a comment |
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
]
);
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
|
show 5 more comments
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
]
);
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
|
show 5 more comments
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
]
);
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
]
);
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
|
show 5 more comments
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
|
show 5 more comments
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?')
);
add a comment |
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?')
);
add a comment |
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?')
);
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?')
);
answered May 4 '16 at 10:52
Raphael at Digital PianismRaphael at Digital Pianism
54.6k22119277
54.6k22119277
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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