Permalink
Browse files

feat(components): actions gets index and value from collection

- when no key is passed the model is passed instead
- collection type adds index property to the schema's elements
- actions.action function gets as callback the value, collection.index and event
  • Loading branch information...
bas080
bas080 committed Jul 1, 2016
1 parent 67f67dd commit 3d3ff3853d0cca64758cd16a82bb04dae308e21e
@@ -23,7 +23,7 @@ export class FormField {

attached() {
if (!existy(this.element.key)) {
logger.error('an element key propery cannot be null or undefined');
logger.debug(`are you sure ${this.element.type} does not have a key`);
}
}

@@ -1,10 +1,17 @@
<template>

<form-field
<form-field repeat.for="element of schema"
if.bind="hasKeyProp(element)"
value.bind="model[element.key]"
message.bind="messages[element.key]"
element.bind="element"
repeat.for="element of schema">
element.bind="element">
</form-field>

<form-field repeat.for="element of schema"
if.bind="!hasKeyProp(element)"
value.bind="model"
message.bind="messages[element.key]"
element.bind="element">
</form-field>

</template>
@@ -17,4 +17,8 @@ export class FormFields {
logger.warn(`model is not an object`);
}
}

hasKeyProp(element) {
return !!element.key;
}
}
@@ -1,8 +1,8 @@
export class Actions {

activate(model) {
this.element = model.element;
this.model = model.value;
console.log(model);
this.value = model.value
}

}
@@ -7,7 +7,7 @@
class="btn btn-default"
type="button"
attributes.bind="action.attributes"
click.delegate="action.action($event)">
click.delegate="action.action(value, element.index, $event)">
${action.label}
</button>
</div>
@@ -2,11 +2,10 @@
<require from="./../../../attributes"></require>
<require from="./form-group"></require>
<form-group element.bind="element" message.bind="message">
<form-fields
attributes.bind="element.attributes"
repeat.for="model of models"
<form-fields repeat.for="model of models"
attributes.bind="element.schema.attributes"
model.bind="model"
schema.bind="element.schema">
schema.bind="schema($index)">
</form-fields>
</form-group>
</template>
@@ -1,8 +1,18 @@
import {computedFrom} from 'aurelia-framework';
export class Collection {

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

/* @note the collection element sets index on every element, consider the
* index property on the schema reserved for the collection element */
this.schema = (index) => {
return this.element.schema.map(element => {
let el = Object.create(element);
el.index = index;
return el;
});
};
}
}

0 comments on commit 3d3ff38

Please sign in to comment.