Permalink
Browse files

feat(component): working implementation of conditional type form field

  • Loading branch information...
bas080
bas080 committed Jul 3, 2016
1 parent 81bd989 commit 92c643dfa56983bb19c2f14cf42e8dafbebf3dbb
@@ -23,6 +23,7 @@ export function configure(aurelia, configCallback) {
/* custom elements with a view model do not end with .html */
actions : '{{framepath}}/actions',
collection : '{{framepath}}/collection',
conditional : '{{framepath}}/conditional',

/* all input components */
button : '{{framepath}}/input.html',
@@ -1,7 +1,7 @@
export class Actions {

activate(model) {
this.value = model.value
this.value = model.value;
}

}
@@ -0,0 +1,6 @@
<template>
<form-fields
schema.bind="schema"
model.bind="model">
</form-fields>
</template>
@@ -0,0 +1,5 @@
import {customElement} from 'aurelia-framework';
import {Conditional as Base} from '../conditional';

@customElement('conditional')
export class ConditionalCustomElement extends Base {}
@@ -1,4 +1,3 @@
import {computedFrom} from 'aurelia-framework';
export class Collection {

activate(model) {
@@ -0,0 +1,29 @@
import {BindingEngine, inject} from 'aurelia-framework';

@inject(BindingEngine)
export class Conditional {

constructor(bindingEngine) {
this.bindingEngine = bindingEngine;
}

activate(field) {
this.model = field.value;

const calculateSchema = () => {
this.schema = field.element.schema(this.model);
};

calculateSchema();

if (typeof this.model === 'object' && field.element.observe) {
this.observer = this.bindingEngine.propertyObserver(this.model, field.element.observe)
.subscribe(calculateSchema);
}
}

deactivate() {
this.observer && this.observer.dispose();
}

}

0 comments on commit 92c643d

Please sign in to comment.