Skip to content

Instantly share code, notes, and snippets.

@djedi
Last active January 5, 2018 17:09
Show Gist options
  • Select an option

  • Save djedi/f57a74d904525e243146af6ee46de86b to your computer and use it in GitHub Desktop.

Select an option

Save djedi/f57a74d904525e243146af6ee46de86b to your computer and use it in GitHub Desktop.

Revisions

  1. djedi revised this gist Jan 5, 2018. 2 changed files with 9 additions and 7 deletions.
    2 changes: 1 addition & 1 deletion my-radio-holder.html
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,3 @@
    <template>
    <div id.bind="id"><slot></slot></div>
    <div><slot></slot></div>
    </template>
    14 changes: 8 additions & 6 deletions my-radio-holder.js
    Original file line number Diff line number Diff line change
    @@ -1,14 +1,16 @@
    import {bindable} from 'aurelia-framework';
    import {bindable, inject} from 'aurelia-framework';

    @inject(Element)
    export class MyRadioHolder {
    @bindable name;
    @bindable id = Math.random().toString(36).slice(-7);

    constructor(element) {
    this.element = element;
    }

    attached() {
    let elem = document.getElementById(this.id);
    if (elem.tagName === 'MY-RADIO-HOLDER') {
    elem = elem.children[0];
    }
    console.debug('[this.element]', this.element.children[0]);
    let elem = this.element.children[0];
    elem.childNodes.forEach((n) => {
    if (n.tagName === 'MY-RADIO') {
    n.children[0].name = this.name;
  2. djedi created this gist Jan 5, 2018.
    9 changes: 9 additions & 0 deletions app.html
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,9 @@
    <template>
    <require from="./my-radio-holder"></require>
    <require from="./my-radio"></require>

    <my-radio-holder name="myname" id="force"> <!-- id is optional -->
    <my-radio>Option 1</my-radio>
    <my-radio>Option 2</my-radio>
    </my-radio-holder>
    </template>
    3 changes: 3 additions & 0 deletions app.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,3 @@
    export class App {

    }
    18 changes: 18 additions & 0 deletions index.html
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,18 @@
    <!doctype html>
    <html>
    <head>
    <title>Aurelia</title>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    </head>
    <body aurelia-app>
    <h1>Loading...</h1>

    <script src="https://jdanyow.github.io/rjs-bundle/node_modules/requirejs/require.js"></script>
    <script src="https://jdanyow.github.io/rjs-bundle/config.js"></script>
    <script src="https://jdanyow.github.io/rjs-bundle/bundles/aurelia.js"></script>
    <script src="https://jdanyow.github.io/rjs-bundle/bundles/babel.js"></script>
    <script>
    require(['aurelia-bootstrapper']);
    </script>
    </body>
    </html>
    3 changes: 3 additions & 0 deletions my-radio-holder.html
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,3 @@
    <template>
    <div id.bind="id"><slot></slot></div>
    </template>
    18 changes: 18 additions & 0 deletions my-radio-holder.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,18 @@
    import {bindable} from 'aurelia-framework';

    export class MyRadioHolder {
    @bindable name;
    @bindable id = Math.random().toString(36).slice(-7);

    attached() {
    let elem = document.getElementById(this.id);
    if (elem.tagName === 'MY-RADIO-HOLDER') {
    elem = elem.children[0];
    }
    elem.childNodes.forEach((n) => {
    if (n.tagName === 'MY-RADIO') {
    n.children[0].name = this.name;
    }
    })
    }
    }
    3 changes: 3 additions & 0 deletions my-radio.html
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,3 @@
    <template>
    <input type="radio" id.bind="id"><slot></slot></input>
    </template>
    3 changes: 3 additions & 0 deletions my-radio.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,3 @@
    export class MyRadio {

    }