Proposal for an acceptably minimal means for storing a list of values
ssokolow opened this issue · comments
One thing I find myself reinventing over and over again when using GM_config is a means to store a list of things (numeric IDs, tags, substrings to match, regular expressions) and I always wind up doing it with either a comma-separated text
list that may be parsed into an int
list internally or a "one entry per line" textarea
.
While I understand your reasoning for not providing custom field types for everything and I understand not supporting the general case, supporting non-nested lists would massively expand the utility of the basic GM_config functionality with minimal code bloat.
What I propose is some kind of list_delimiter
parameter that allows fields like text
, int
, float
, and textarea
to accept and validate comma- or newline-delimited input as appropriate.
...something akin to this Python code:
list_delim = field_config.get('list_delimiter')
if list_delim:
field_val = field_val.split(list_delim)
else:
field_val = [field_val]
for val in field_val:
# Do the usual validation
Failing that, perhaps a clearly documented means for hooking in at various stages in the processing so I could wrap the equivalent JavaScript in a callback rather than reinventing the entire validation process?
You could implement this as a custom field type. See the relevant wiki section and the example: Custom field types.
And my other comment?
Failing that, perhaps a clearly documented means for hooking in at various stages in the processing so I could wrap the equivalent JavaScript in a callback rather than reinventing the entire validation process?
See this example
Thanks. :)