Fix select default option extraction

This commit is contained in:
Rob Garrison 2018-09-17 22:10:43 -05:00
parent 153a066fbe
commit 7d533d4d4a

View File

@ -194,30 +194,18 @@ var usercss = (() => {
state.errorPrefix = 'Invalid JSON: '; state.errorPrefix = 'Invalid JSON: ';
parseJSONValue(state); parseJSONValue(state);
state.errorPrefix = ''; state.errorPrefix = '';
const extractDefault = text => { const extractDefaultOption = (key, value) => {
if (text.endsWith('*')) { if (key.endsWith('*')) {
return text.slice(0, -1); const option = createOption(key.slice(0, -1), value);
result.default = option.name;
return option;
} }
return false; return createOption(key, value);
}; };
if (Array.isArray(state.value)) { if (Array.isArray(state.value)) {
result.options = state.value.map(text => { result.options = state.value.map(k => extractDefaultOption(k));
const isDefault = extractDefault(text);
if (isDefault) {
result.default = isDefault;
}
return createOption(isDefault || text);
});
} else { } else {
result.options = Object.keys(state.value).map(k => { result.options = Object.keys(state.value).map(k => extractDefaultOption(k, state.value[k]));
const isDefault = extractDefault(k);
const value = state.value[k];
if (isDefault) {
k = isDefault;
result.default = k;
}
return createOption(k, value);
});
} }
if (result.default === null) { if (result.default === null) {
result.default = (result.options[0] || {}).name || ''; result.default = (result.options[0] || {}).name || '';