I am developing a custom module in Magento 2.0.9 and writing the system.xml file to allow users to make some settings from backend.
Now I need to show a Radio button in custom module backend settings section. This is what I wrote in system.xml
<field id="box_small_left_h_alignment" translate="label" type="radio" sortOrder="31" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Horizontal Alignment</label>
<source_model>SG\Slider\Model\Backend\Options\HorizontalAlignment</source_model>
</field>
And this is the source model:
<?php
namespace SG\Slider\Model\Backend\Options;
class HorizontalAlignment implements \Magento\Framework\Option\ArrayInterface {
public function toOptionArray()
{
return [['value' => 'left', 'label' => __('Left')], ['value' => 'right', 'label' => __('Right')],];
}
}
Doing in this way no error are thrown in the backend but my radio field has no options. What am I missing?
1 Answer 1
You have to use radios instead of radio as field type.
answered Jan 3, 2017 at 13:13
WaPoNe
1,6483 gold badges18 silver badges36 bronze badges
-
1This does not provide an answer to the question. To critique or request clarification from an author, leave a comment below their post. - From Review7ochem– 7ochem2017年01月03日 13:33:17 +00:00Commented Jan 3, 2017 at 13:33
-
1I'm sorry but I don't understand you.. my answer provides a solution to the question. The issue is due to the use of
radioinstead ofradios; I've also tested it and it works fine.WaPoNe– WaPoNe2017年01月03日 14:39:50 +00:00Commented Jan 3, 2017 at 14:39
default
return [['value' => 'left', 'label' => __('Left')], ['value' => 'right', 'label' => __('Right')],];