Created
December 18, 2016 21:40
-
-
Save jdanyow/8b8f6c593612ec0e64d53501745f7103 to your computer and use it in GitHub Desktop.
select2 multiple example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<template> | |
<require from="select2-custom-attribute"></require> | |
<h1>Standard Select</h1> | |
<select multiple value.bind="selectedThing" style="width: 100%"> | |
<option repeat.for="thing of things" model.bind="thing">${thing.name}</option> | |
</select> | |
<ul> | |
<li repeat.for="thing of selectedThing">${thing.name}</li> | |
</ul> | |
<h1>Select2</h1> | |
<div> | |
<select select2 multiple value.bind="selectedThing2" style="width: 100%"> | |
<option repeat.for="thing of things" model.bind="thing">${thing.name}</option> | |
</select> | |
</div> | |
<ul> | |
<li repeat.for="thing of selectedThing2">${thing.name}</li> | |
</ul> | |
</template> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export class App { | |
things = [ | |
{ id: 0, name: 'foo' }, | |
{ id: 1, name: 'bar'}, | |
{ id: 2, name: 'baz'}]; | |
selectedThing = []; | |
selectedThing2 = []; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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 type="text/javascript" src="https://select2.github.io/vendor/js/jquery.min.js"></script> | |
<script type="text/javascript" src="https://select2.github.io/dist/js/select2.full.js"></script> | |
<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> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import {customAttribute, inject} from 'aurelia-framework'; | |
@customAttribute('select2') | |
@inject(Element) | |
export class Select2CustomAttribute { | |
constructor(element) { | |
this.element = element; | |
} | |
attached() { | |
$(this.element).select2(this.value) | |
.on('change', (e) => { | |
if (e.originalEvent) { | |
return; | |
} | |
this.element.dispatchEvent(new Event('change')); | |
}); | |
} | |
detached() { | |
$(this.element).select2('destroy'); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment