sizzlemctwizzle / GM_config

A lightweight, reusable, cross-browser graphical settings framework for inclusion in user scripts.
https://github.com/sizzlemctwizzle/GM_config/wiki
GNU Lesser General Public License v3.0
205 stars 48 forks source link

Allow option names for select field, small radio field corrections (issue #69 ) #107

Closed maddes-b closed 1 year ago

maddes-b commented 2 years ago

Allow option names for select fields via multi-dimensional array or a "Dictionary" Object with "optvalue": "optname" pairs. It is backwards compatible with the current options array, that contains only strings for the values.

Examples:

var options = [ // multi-dimensional array
  [ "val1", "name1" ],
  [ "val2" ], // value will be used as name
  "val3", // value will be used as name (backwards compatibility)
];
var options = { // "Dictionary" object
  "val1": "name1",
  "val2": "", // value will be used as name
}

Additional:

References:

maddes-b commented 2 years ago

Can already be used with the current lib version by replacing the functions for select fields:

GM_config.init({
    'id': 'myUserScript', // GM_config instance id
    'fields':
    {
        'locale': // This is the id of the field
        {
            'label': 'Select a locale', // Appears next to field
            'type': 'select',
            'options': locales,
            'default': 'en'
        },
    },
    types:
    {
        select:
        {
// --- HERE: copy the toNode, toValue and reset functions from the pull request
  toNode: function() {
...
  },

  toValue: function() {
...
  },

  reset: function() {
...
  },
// ------------------------------------------------------------
        }
    },
});

That is from line 601 to line 869.

sizzlemctwizzle commented 1 year ago

69 will be handled by the new milestone (see #108), so a PR will eventually come attached to that, meaning that this is a future duplicate PR. Yes, I know I'm a bit of a control freak when it comes to GM_config. Sorry, not sorry.

Until then people can used the suggested workaround.