ChangeData.js
2 years ago
CheckboxData.js
2 years ago
InputData.js
2 years ago
InputMaskedData.js
2 years ago
MultiSelectData.js
2 years ago
NoListenData.js
2 years ago
RadioData.js
2 years ago
RangeData.js
2 years ago
RenderStateData.js
2 years ago
WysiwygData.js
2 years ago
functions.js
2 years ago
MultiSelectData.js
40 lines
| 1 | import InputData from './InputData'; |
| 2 | import { isMultiSelect } from '../supports'; |
| 3 | import ReactiveHook from '../reactive/ReactiveHook'; |
| 4 | |
| 5 | function MultiSelectData() { |
| 6 | InputData.call( this ); |
| 7 | |
| 8 | this.isSupported = function ( node ) { |
| 9 | return isMultiSelect( node ); |
| 10 | }; |
| 11 | this.addListeners = function () { |
| 12 | this.sanitize( value => Array.isArray( value ) ? value : [ value ] ); |
| 13 | |
| 14 | const [ node ] = this.nodes; |
| 15 | |
| 16 | node.addEventListener( 'change', () => this.setValue() ); |
| 17 | node.addEventListener( 'blur', () => this.reportOnBlur() ); |
| 18 | |
| 19 | this.enterKey = new ReactiveHook(); |
| 20 | node.addEventListener( 'keydown', this.handleEnterKey.bind( this ) ); |
| 21 | }; |
| 22 | this.setValue = function () { |
| 23 | this.value.current = this.getActiveValue(); |
| 24 | }; |
| 25 | this.getActiveValue = function () { |
| 26 | const [ node ] = this.nodes; |
| 27 | |
| 28 | return Array.from( node.options ). |
| 29 | filter( item => item.selected ). |
| 30 | map( item => item.value ); |
| 31 | }; |
| 32 | |
| 33 | this.onClear = function () { |
| 34 | this.silenceSet( [] ); |
| 35 | }; |
| 36 | } |
| 37 | |
| 38 | MultiSelectData.prototype = Object.create( InputData.prototype ); |
| 39 | |
| 40 | export default MultiSelectData; |