2

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?

asked Sep 28, 2016 at 15:03
1
  • Try to delete the last comma in this instruction: return [['value' => 'left', 'label' => __('Left')], ['value' => 'right', 'label' => __('Right')],]; Commented Jan 3, 2017 at 11:29

1 Answer 1

2

You have to use radios instead of radio as field type.

answered Jan 3, 2017 at 13:13
2
  • 1
    This does not provide an answer to the question. To critique or request clarification from an author, leave a comment below their post. - From Review Commented Jan 3, 2017 at 13:33
  • 1
    I'm sorry but I don't understand you.. my answer provides a solution to the question. The issue is due to the use of radio instead of radios; I've also tested it and it works fine. Commented Jan 3, 2017 at 14:39

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.