-
-
Save VagyokC4/8d3479bc1054f5ca340257c4c1f6afc8 to your computer and use it in GitHub Desktop.
select2 placeholder 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>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> |
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'}]; | |
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"> | |
<link rel = "stylesheet" | |
type = "text/css" | |
href = "https://app.pashiontool.com/jspm_packages/github/select2/[email protected]/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> |
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