Sha256: 0352b4cec508d706f24ea8d866748efde6797a27c911d27435c3b6602e130062

Contents?: true

Size: 1.56 KB

Versions: 18

Compression:

Stored size: 1.56 KB

Contents

import {MDCSelect} from '@material/select';
import {VBaseComponent, hookupComponents} from './base-component';
import {visibilityObserverMixin} from "./mixins/visibility-observer";
import {dirtyableMixin} from './mixins/dirtyable';

export function initSelects(e) {
    console.debug('\tSelects');
    hookupComponents(e, '.v-select', VSelect, MDCSelect);
}

export class VSelect extends dirtyableMixin(visibilityObserverMixin(VBaseComponent)) {
    constructor(element, mdcComponent) {
        super(element, mdcComponent);
        this.select = element.querySelector('select');
        this.select.vComponent = this;
        this.recalcWhenVisible(this);
        this.originalValue = this.value();
    }

    prepareSubmit(params) {
        params.push([this.name(), this.value()]);
    }

    name() {
        return this.select.name;
    }

    value() {
        return this.select.options.length === 0 || this.select.selectedIndex === -1 ? null : this.select.options[this.select.selectedIndex].value;
    }

    clear() {
        let before = this.select.selectedIndex;
        this.select.selectedIndex = 0;
        if (before !== 0) {
            var event = new InputEvent('input', {
                view: window,
                bubbles: true,
                cancelable: true
              });
            this.select .dispatchEvent(event);
        }
    }

    reset() {
        this.select.value = this.originalValue;
    }

    setValue(value) {
        this.select.value = value;
    }

    isDirty() {
        return this.dirtyable && this.value() !== this.originalValue;
    }
}

Version data entries

18 entries across 18 versions & 2 rubygems

Version Path
coprl-3.0.0.beta.12 views/mdc/assets/js/components/selects.js
coprl-3.0.0.beta.11 views/mdc/assets/js/components/selects.js
coprl-3.0.0.beta.10 views/mdc/assets/js/components/selects.js
coprl-3.0.0.beta.9 views/mdc/assets/js/components/selects.js
coprl-3.0.0.beta.8 views/mdc/assets/js/components/selects.js
coprl-3.0.0.beta.7 views/mdc/assets/js/components/selects.js
coprl-3.0.0.beta.6 views/mdc/assets/js/components/selects.js
coprl-3.0.0.beta.5 views/mdc/assets/js/components/selects.js
voom-presenters-2.1.2 views/mdc/assets/js/components/selects.js
coprl-3.0.0.beta.4 views/mdc/assets/js/components/selects.js
coprl-3.0.0.beta.3 views/mdc/assets/js/components/selects.js
coprl-3.0.0.beta.2 views/mdc/assets/js/components/selects.js
coprl-3.0.0.beta.1 views/mdc/assets/js/components/selects.js
voom-presenters-2.1.0 views/mdc/assets/js/components/selects.js
voom-presenters-2.0.3 views/mdc/assets/js/components/selects.js
voom-presenters-2.0.2 views/mdc/assets/js/components/selects.js
voom-presenters-2.0.1 views/mdc/assets/js/components/selects.js
voom-presenters-2.0.0 views/mdc/assets/js/components/selects.js