Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add radio button group element to plugin config page #626

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

nooogent
Copy link

This PR adds the ability to use a group of radio buttons on Plugin config pages.

Can be used as follows in a plugin UIConfig.json file:

   {
      "id": "myRadioId",
      "element": "radio",
      "options": [
        {
          "label":"TRANSLATE.OPTION_ONE",
          "name": "optionOne",
          "value": "1"
        },
        {
          "label":"TRANSLATE.OPTION_TWO",
          "name": "optionTwo",
          "value": "2"
        }
      ],
      "value": "1",
      "label": "TRANSLATE.MY_RADIO_LABEL"
    }

When the section is saved the value returned for the element will be the value of the selected option.

myplugin.prototype.setUIConfig = function (data) {
config.set('myConfigItem', data['myRadioId']);
}

Setting the value of the radio element in the plugin controller will result in the correct radio option being selected when the plugin config page is loaded.

myplugin.prototype.getUIConfig = function () {
var lang_code = this.commandRouter.sharedVars.get('language_code');
return this.commandRouter.i18nJson(_dirname + '/i18n/strings' + lang_code + '.json',
__dirname + '/i18n/strings_en.json',
__dirname + '/UIConfig.json')
.then(function (uiconf) {
// radio button group element
uiconf.sections[0].content[0].value = config.get('myConfigItem');
return uiconf;
})
.fail(function () {
libQ.reject(new Error());
});
};

@Tristenax
Copy link
Contributor

Hi, @nooogent,
thanks for the PR, you did a great job with the menu change when an option is selected but you should change the radio button with a dropdown menu.

Let me know what you think

@nooogent
Copy link
Author

Thanks for the feedback @Tristenax

There are a number of reasons why I think that someone might want to use radio buttons rather than a dropdown. For example in relation to the autostart plugin config page I think it makes sense because:

  1. The options need to be emphasized, the options available are not homogeneous, so it's not like selecting a single dac from a list of dacs in a dropdown.
  2. There are a small number of options.
  3. The user doesn't have to open a dropdown to compare available options.
  4. There is no obvious default option.

I actually tried to get the plugin-visible directive to work with the select element, but had no luck. I think it is because the "value" property of the selected element is a complex object rather than a value type.

@volumio volumio changed the base branch from development to master March 19, 2020 12:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants