MCPcopy
hub / github.com/apache/echarts / initSelectInputOptions

Function initSelectInputOptions

test/lib/testHelper.js:1169–1247  ·  view source on GitHub ↗
(inputDefine)

Source from the content-addressed store, hash-verified

1167 }
1168
1169 function initSelectInputOptions(inputDefine) {
1170 // optionDef can be {text, value} or just value
1171 // (value can be null/undefined/array/object/... everything).
1172 // Convinient but might cause ambiguity when a value happens to be {text, value}, but rarely happen.
1173 if (inputDefine.options) {
1174 var innerInputCount = 0;
1175 for (var optionIdx = 0; optionIdx < inputDefine.options.length; optionIdx++) {
1176 var optionDef = inputDefine.options[optionIdx];
1177 assert(isObject(optionDef), [
1178 errMsgPrefix + ' Select option definition should be an object, such as,',
1179 _SAMPLE_SELECT_DEFINITION
1180 ].join('\n'));
1181 assert(optionDef.hasOwnProperty('value') || isObject(optionDef.input), [
1182 errMsgPrefix + ' Select option definition should contain prop'
1183 + ' either `value` or `option`, such as,',
1184 _SAMPLE_SELECT_DEFINITION
1185 ].join('\n'));
1186 var text = getType(optionDef.text) === 'string'
1187 ? optionDef.text
1188 : makeSelectInputTextByValue(optionDef);
1189 selectCtx._optionList.push({
1190 value: optionDef.value,
1191 input: optionDef.input,
1192 id: optionDef.id,
1193 text: text
1194 });
1195 if (optionDef.input) {
1196 innerInputCount++;
1197 }
1198 assert(innerInputCount < 2 || optionDef.id != null, [
1199 errMsgPrefix + ' If more than one inner input in a select,'
1200 + ' option id must be specified. ',
1201 _SAMPLE_SELECT_DEFINITION
1202 ].join('\n'));
1203 }
1204 }
1205 else if (inputDefine.values) {
1206 for (var optionIdx = 0; optionIdx < inputDefine.values.length; optionIdx++) {
1207 var value = inputDefine.values[optionIdx];
1208 selectCtx._optionList.push({
1209 value: value,
1210 text: makeSelectInputTextByValue({value: value})
1211 });
1212 }
1213 }
1214 if (!selectCtx._optionList.length) {
1215 throw new Error(errMsgPrefix + ' No options specified for select.');
1216 }
1217
1218 for (var optionIdx = 0; optionIdx < selectCtx._optionList.length; optionIdx++) {
1219 var optionDef = selectCtx._optionList[optionIdx];
1220 selectCtx._optionList[optionIdx] = optionDef;
1221 var optionEl = document.createElement('option');
1222 optionEl.innerHTML = encodeHTML(optionDef.text);
1223 // HTML select.value is always string. But it would be more convenient to
1224 // convert it to user's raw input value type.
1225 // (The input raw value can be null/undefined/array/object/... everything).
1226 optionEl.value = optionIdx;

Callers 1

createSelectInputFunction · 0.85

Calls 7

encodeHTMLFunction · 0.85
arrayIndexOfFunction · 0.85
createRangeInputFunction · 0.85
assertFunction · 0.70
isObjectFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…