Skip to content
Snippets Groups Projects
Select Git revision
  • 6dd6d32d961bcc48555c384623b4051b45fe8455
  • master default protected
  • 1.31
  • 4.38.3
  • 4.38.2
  • 4.38.1
  • 4.38.0
  • 4.37.2
  • 4.37.1
  • 4.37.0
  • 4.36.0
  • 4.35.0
  • 4.34.1
  • 4.34.0
  • 4.33.1
  • 4.33.0
  • 4.32.2
  • 4.32.1
  • 4.32.0
  • 4.31.0
  • 4.30.1
  • 4.30.0
  • 4.29.1
23 results

table.mjs

Blame
  • 280.mjs 2.63 KiB
    /**
     * @file development/issues/open/280.mjs
     * @url https://gitlab.schukai.com/oss/libraries/javascript/monster/-/issues/280
     * @description select attribute=\"value\" from datasource doesn´t work
     * @issue 280
     */
    
    import "../../../source/components/style/property.pcss";
    import "../../../source/components/style/link.pcss";
    import "../../../source/components/style/color.pcss";
    import "../../../source/components/style/theme.pcss";
    import "../../../source/components/style/normalize.pcss";
    import "../../../source/components/style/typography.pcss";
    import "../../../source/components/form/select.mjs";
    import {assembleMethodSymbol, CustomElement, registerCustomElement} from "../../../source/dom/customelement.mjs";
    
    const dataset = [
        {
            "name": "United Kingdom",
            "alpha-2": "GB",
            "country-code": "826",
        },
        {
            "name": "Sweden",
            "alpha-2": "SE",
            "country-code": "752",
    
        },
        {
            "name": "Germany",
            "alpha-2": "DE",
            "country-code": "276",
        }
    ]
    
    setTimeout(() => {
    
        const select = document.getElementById("i280")
       // console.log(select);
    
        //select.setOption("disabled", true);
    
        select.setOption("test.value", ["826", "752"]);
    
        select.getSelect().setOption('mapping.labelTemplate', '${name} (${alpha-2})')
    
    // the value template is a string that will be used to generate the value for each option
        select.getSelect().setOption('mapping.valueTemplate', '${country-code}')
    
    
        //if(true) return
    
        //document.getElementById("i280").setOption("test.value", "a,b,c");
    
        setTimeout(() => {
    // the label template is a string that will be used to generate the label for each option
    
            select.getSelect().importOptions(dataset);
    
        }, 1000);
    
        //select.setOption("test.value", ["826","752"]);
    
    }, 1000);
    
    
    class Issue280 extends CustomElement {
    
        [assembleMethodSymbol]() {
            super[assembleMethodSymbol]();
        }
    
        get defaults() {
            return Object.assign({}, super.defaults, {
                templates: {
                    main: getTemplate(),
                },
    
                test: {
                    value: ["826"]
                }
    
            });
        }
    
        static getTag() {
            return "monster-issue-280";
        }
    
        getSelect() {
            return this.shadowRoot.querySelector("monster-select");
        }
    
    }
    
    
    /**
     * @private
     * @return {string}
     */
    function getTemplate() {
        // language=HTML
        return `
            <div data-monster-role="control" part="control">
    
                <monster-select data-monster-attributes="value path:test.value" data-monster-option-type="checkbox">
    
                </monster-select>
    
    
            </div>
        `;
    }
    
    
    registerCustomElement(Issue280);