Skip to content

Instantly share code, notes, and snippets.

@fabioluz
Last active March 14, 2017 14:56
Show Gist options
  • Save fabioluz/45617c25421eac37be599595d7fda593 to your computer and use it in GitHub Desktop.
Save fabioluz/45617c25421eac37be599595d7fda593 to your computer and use it in GitHub Desktop.
<template>
<require from="./element"></require>
<element></element>
</template>
export class App {
message = 'Hello World!';
}
<template>
<input type='text' value.bind='input & debounce' focus.bind='hasFocus'>
<div if.bind='results.length'>
${results.length}
<div repeat.for='result of results' click.delegate='selectOption(result)'>
${result}
</div>
</div>
</template>
import {
inject,
customElement,
containerless,
bindable,
bindingMode,
observable
} from 'aurelia-framework';
@customElement('element')
@containerless()
export class Autosearch {
@observable input;
constructor() {
this.results = []; // input focus with a delay before blur.
this.model = {
options: ['Foobar','Barfoo','HelloWorld'],
selected: null
}
}
attached() {
this.input = this.model.selected || '';
}
inputChanged(newValue) {
if (newValue === this.model.selected) {
return;
}
let pattern = newValue.toLowerCase();
this.results = this.model.options.filter(x =>
x.toLowerCase().indexOf(pattern) > 0);
}
selectOption(value) {
this.model.selected = value;
this.input = value;
this.results = [];
//setArray(this.results, []); // FIXME Necessary to prevent a crash in aurelia templating. No idea why.
}
}
<!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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment