Add default select option. See #492

This commit is contained in:
Rob Garrison 2018-09-04 21:18:08 -05:00
parent 74892a3130
commit 9b483d993b

View File

@ -177,6 +177,7 @@ var usercss = (() => {
result.label = state.value;
const {re, type, text} = state;
let deflt;
switch (type === 'image' && state.key === 'var' ? '@image@var' : type) {
case 'checkbox': {
@ -195,11 +196,24 @@ var usercss = (() => {
parseJSONValue(state);
state.errorPrefix = '';
if (Array.isArray(state.value)) {
result.options = state.value.map(text => createOption(text));
} else {
result.options = Object.keys(state.value).map(k => createOption(k, state.value[k]));
result.options = state.value.map(text => {
if (text.endsWith('*')) {
text = text.replace(/\*$/, '');
deflt = text;
}
result.default = (result.options[0] || {}).name || '';
return createOption(text);
});
} else {
result.options = Object.keys(state.value).map(k => {
if (k.endsWith('*')) {
state.value[k] = state.value[k].replace(/\*$/, '');
k = k.replace(/\*$/, '');
deflt = k;
}
return createOption(k, state.value[k]);
});
}
result.default = typeof deflt !== 'undefined' ? deflt : (result.options[0] || {}).name || '';
break;
}