Skip to content

Instantly share code, notes, and snippets.

@VagyokC4
Forked from jdanyow/app.html
Last active May 9, 2017 15:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save VagyokC4/8d3479bc1054f5ca340257c4c1f6afc8 to your computer and use it in GitHub Desktop.
Save VagyokC4/8d3479bc1054f5ca340257c4c1f6afc8 to your computer and use it in GitHub Desktop.
select2 placeholder example
<template>
<require from="select2-custom-attribute"></require>
<h1>Select2</h1>
<div>
<select select2.bind='{ "placeholder": "Action", "allowClear": true, "minimumResultsForSearch": -1}' value.bind="selectedThing2" style="width: 100%">
<option></option>
<option value="Pending">Pending</option>
<option value="Approved">Approve</option>
<option value="Denied">Deny</option>
</select>
</div>
<div>
${selectedThing2}
</div>
</template>
export class App {
things = [
{ id: 0, name: 'foo' },
{ id: 1, name: 'bar'},
{ id: 2, name: 'baz'}];
selectedThing2 = '';
}
<!doctype html>
<html>
<head>
<title>Aurelia</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel = "stylesheet"
type = "text/css"
href = "https://app.pashiontool.com/jspm_packages/github/select2/select2@3.5.4/select2.css" />
</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>
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