MCPcopy Index your code
hub / github.com/reactjs/react-rails / updateOptions

Function updateOptions

lib/assets/react-source/development/react.js:5882–5932  ·  view source on GitHub ↗
(node, multiple, propValue, setDefaultSelected)

Source from the content-addressed store, hash-verified

5880 }
5881
5882 function updateOptions(node, multiple, propValue, setDefaultSelected) {
5883 var options = node.options;
5884
5885 if (multiple) {
5886 var selectedValues = propValue;
5887 var selectedValue = {};
5888
5889 for (var i = 0; i < selectedValues.length; i++) {
5890 // Prefix to avoid chaos with special keys.
5891 selectedValue['$' + selectedValues[i]] = true;
5892 }
5893
5894 for (var _i = 0; _i < options.length; _i++) {
5895 var selected = selectedValue.hasOwnProperty('$' + options[_i].value);
5896
5897 if (options[_i].selected !== selected) {
5898 options[_i].selected = selected;
5899 }
5900
5901 if (selected && setDefaultSelected) {
5902 options[_i].defaultSelected = true;
5903 }
5904 }
5905 } else {
5906 // Do not set `select.value` as exact behavior isn't consistent across all
5907 // browsers for all cases.
5908 var _selectedValue = toString(getToStringValue(propValue));
5909
5910 var defaultSelected = null;
5911
5912 for (var _i2 = 0; _i2 < options.length; _i2++) {
5913 if (options[_i2].value === _selectedValue) {
5914 options[_i2].selected = true;
5915
5916 if (setDefaultSelected) {
5917 options[_i2].defaultSelected = true;
5918 }
5919
5920 return;
5921 }
5922
5923 if (defaultSelected === null && !options[_i2].disabled) {
5924 defaultSelected = options[_i2];
5925 }
5926 }
5927
5928 if (defaultSelected !== null) {
5929 defaultSelected.selected = true;
5930 }
5931 }
5932 }
5933 /**
5934 * Implements a <select> host component that allows optionally setting the
5935 * props `value` and `defaultValue`. If `multiple` is false, the prop must be a

Callers 3

postMountWrapper$2Function · 0.85
postUpdateWrapperFunction · 0.85
restoreControlledState$1Function · 0.85

Calls 2

toStringFunction · 0.85
getToStringValueFunction · 0.85

Tested by

no test coverage detected