GM_config icon indicating copy to clipboard operation
GM_config copied to clipboard

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

Open maddes-b opened this issue 2 years ago • 1 comments

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:

  • correct reset function of select fields (was checking text instead of value)
  • correct reset function of radio fields (not clearing all states)
  • enhance toValue function of radio fields with early-out when selected value found
  • add VSCode settings to align with style of original author

References:

  • Issue #69

maddes-b avatar Nov 06 '22 00:11 maddes-b

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.

maddes-b avatar Nov 06 '22 01:11 maddes-b

#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.

sizzlemctwizzle avatar May 06 '23 20:05 sizzlemctwizzle