src/aria/widgets/form/list/ListController.js
function (newValues) {
            var arrayUtil = ariaUtilsArray;

            this._stopUpdates();
            var newlySelectedIndexes = [];
            var newlyUnselectedIndexes = [];

            // Loop through all of the items and update the selection status for each item,
            // depending on the new array of selected values
            var selectedIndex = -1;
            var data = this._data;
            var items = data.items;
            var maxSelectedCount = this._getTrueMaxSelectedCount(items);
            var selectedCount = 0;
            for (var idx = 0, length = items.length; idx < length; idx++) {
                var item = items[idx];
                var selected = arrayUtil.contains(newValues, item.value);
                if (selected) {
                    if (selectedCount == maxSelectedCount) {
                        // cancel selection when there is more than what is allowed
                        selected = false;
                    } else if (selectedIndex == -1) {
                        selectedCount = 1;
                        selectedIndex = idx;
                    } else {
                        selectedCount++;
                        selectedIndex = null;
                    }
                }
                if (data.preselect === "none" || item.selected != selected) {
                    // selection has changed
                    (selected ? newlySelectedIndexes : newlyUnselectedIndexes).push(idx);
                    this.json.setValue(items[idx], "selected", selected);
                }
            }
            this.json.setValue(data, "selectedIndex", selectedIndex);
            this.json.setValue(data, "selectedCount", selectedCount);

            // James removed this because if more than one item is selected, data. selectedIndex is set to null.
            // Also, in the case of the multi-select we don't necessarily
            // Want to focus a selected item - need to check this on the list.
            // this.json.setValue(data, "focusIndex", selectedIndex);
            // this.setFocus(data.focusIndex);

            this._updateCurrentlyDisabled(items);
            this._resumeUpdates();
            if (newlySelectedIndexes.length > 0 || newlyUnselectedIndexes.length > 0) {
                this._raiseOnChangeEvent(newlySelectedIndexes, newlyUnselectedIndexes);
            }
        }
function (newValues) {
            var arrayUtil = ariaUtilsArray;

            this._stopUpdates();
            var newlySelectedIndexes = [];
            var newlyUnselectedIndexes = [];

            // Loop through all of the items and update the selection status for each item,
            // depending on the new array of selected values
            var selectedIndex = -1;
            var data = this._data;
            var items = data.items;
            var maxSelectedCount = this._getTrueMaxSelectedCount(items);
            var selectedCount = 0;
            for (var idx = 0, length = items.length; idx < length; idx++) {
                var item = items[idx];
                var selected = arrayUtil.contains(newValues, item.value);
                if (selected) {
                    if (selectedCount == maxSelectedCount) {
                        // cancel selection when there is more than what is allowed
                        selected = false;
                    } else if (selectedIndex == -1) {
                        selectedCount = 1;
                        selectedIndex = idx;
                    } else {
                        selectedCount++;
                        selectedIndex = null;
                    }
                }
                if (data.preselect === "none" || item.selected != selected) {
                    // selection has changed
                    (selected ? newlySelectedIndexes : newlyUnselectedIndexes).push(idx);
                    this.json.setValue(items[idx], "selected", selected);
                }
            }
            this.json.setValue(data, "selectedIndex", selectedIndex);
            this.json.setValue(data, "selectedCount", selectedCount);

            // James removed this because if more than one item is selected, data. selectedIndex is set to null.
            // Also, in the case of the multi-select we don't necessarily
            // Want to focus a selected item - need to check this on the list.
            // this.json.setValue(data, "focusIndex", selectedIndex);
            // this.setFocus(data.focusIndex);

            this._updateCurrentlyDisabled(items);
            this._resumeUpdates();
            if (newlySelectedIndexes.length > 0 || newlyUnselectedIndexes.length > 0) {
                this._raiseOnChangeEvent(newlySelectedIndexes, newlyUnselectedIndexes);
            }
        }
function ( newValues ) { var arrayUtil = ariaUtilsArray ; this . _stopUpdates ( ) ; var newlySelectedIndexes = [ ] ; var newlyUnselectedIndexes = [ ] ; // Loop through all of the items and update the selection status for each item, // depending on the new array of selected values var selectedIndex = - 1 ; var data = this . _data ; var items = data . items ; var maxSelectedCount = this . _getTrueMaxSelectedCount ( items ) ; var selectedCount = 0 ; for ( var idx = 0 , length = items . length ; idx < length ; idx ++ ) { var item = items [ idx ] ; var selected = arrayUtil . contains ( newValues , item . value ) ; if ( selected ) { if ( selectedCount == maxSelectedCount ) { // cancel selection when there is more than what is allowed selected = false ; } else if ( selectedIndex == - 1 ) { selectedCount = 1 ; selectedIndex = idx ; } else { selectedCount ++ ; selectedIndex = null ; } } if ( data . preselect === "none" || item . selected != selected ) { // selection has changed ( selected ? newlySelectedIndexes : newlyUnselectedIndexes ) . push ( idx ) ; this . json . setValue ( items [ idx ] , "selected" , selected ) ; } } this . json . setValue ( data , "selectedIndex" , selectedIndex ) ; this . json . setValue ( data , "selectedCount" , selectedCount ) ; // James removed this because if more than one item is selected, data. selectedIndex is set to null. // Also, in the case of the multi-select we don't necessarily // Want to focus a selected item - need to check this on the list. // this.json.setValue(data, "focusIndex", selectedIndex); // this.setFocus(data.focusIndex); this . _updateCurrentlyDisabled ( items ) ; this . _resumeUpdates ( ) ; if ( newlySelectedIndexes . length > 0 || newlyUnselectedIndexes . length > 0 ) { this . _raiseOnChangeEvent ( newlySelectedIndexes , newlyUnselectedIndexes ) ; } }
Set the list of selected values.
@param {Array} newValues
Set the list of selected values .