Skip to content

Instantly share code, notes, and snippets.

@si2030
Last active March 25, 2018 00:44
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 si2030/c835b7202aba500c2e079f26d0dd5601 to your computer and use it in GitHub Desktop.
Save si2030/c835b7202aba500c2e079f26d0dd5601 to your computer and use it in GitHub Desktop.
Bootstrap custom element example
<template>
<h2>Address</h2>
<form submit.delegate="submit()">
<ul><li repeat.for="error of controller.errors">${error.message}</li></ul>
<label><input type="checkbox" checked.bind="address.personalData"> Personal Data?</label>
<div class="form-group" show.bind="address.personalData">
<label class="control-label" for="street">Street</label>
<input type="text" class="form-control" id="street" placeholder="Street"
value.bind="address.street">
</div>
<div class="form-group" show.bind="address.personalData">
<label class="control-label" for="houseNumber">House #</label>
<input type="text" class="form-control" id="houseNumber" placeholder="House #"
value.bind="address.houseNumber">
</div>
<div class="form-group">
<label class="control-label" for="city">City</label>
<input type="text" class="form-control" id="city" placeholder="City"
value.bind="address.city">
</div>
<div class="form-group">
<label class="control-label" for="zip">Zip</label>
<input type="text" class="form-control" id="zip" placeholder="Zip"
value.bind="address.zip">
</div>
<button type="submit" class="btn btn-primary">Submit</button>
</form>
</template>
import {bindable, inject} from 'aurelia-framework';
export class AddressForm {
@bindable address;
constructor(controllerFactory) {
}
submit() {
this.controller.validate();
}
}
export class Address {
street = '';
houseNumber = '';
zip = '';
city = '';
personalData = false;
}
<template>
<require from="./address-form"></require>
<address-form address.bind="address"></address-form>
</template>
import {Address} from './address';
export class App {
address = new Address();
}
<!doctype html>
<html>
<head>
<title>Aurelia</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">
<style>
address-form {
display: block;
border: 1px solid lightgray;
border-radius: 3px;
max-width: 300px;
margin: 0 auto 15px auto;
padding: 15px;
}
</style>
</head>
<body aurelia-app="main">
<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>
export function configure(aurelia) {
aurelia.use
.standardConfiguration()
.developmentLogging()
.plugin('aurelia-bootstrap');
aurelia.start().then(() => aurelia.setRoot());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment