Permalink
Browse files

fix(naming): schema to attribute and name to key

Code in the form field (singular) used the schema property to store an attribute
of a schema. This is confusing.

The name property of an attribute was changed to key. This better fits existing
standards. It also makes sense as a keyword that represents a property is often
refered to as key.

Also updated version
  • Loading branch information...
bas080
bas080 committed May 23, 2016
1 parent 714c372 commit b2987c9d0b0692eed29831377340a137d58bed0f
@@ -1,6 +1,6 @@
{
"name": "aurelia-form",
"version": "0.0.3",
"version": "0.1.0",
"description": "Makes working with forms just a tad more pleasant.",
"keywords": [
"aurelia",
@@ -4,12 +4,12 @@
* framework component.
*
* @param {object} config
* @param {object} schema
* @param {object} attribute
* @returns {string} which represents the path of either a custom, framework or
* default component
*/
export function component(config, schema) {
let type = schema.type;
export function component(config, attribute) {
let type = attribute.type;

return customComponent() || frameworkComponent();

@@ -1,15 +1,15 @@
<template>
<div class="form-group">
<label if.bind="!schema.hide_label">${label}</label>
<label if.bind="!attribute.hide_label">${label}</label>

<compose
if.bind="isHtmlComponent"
model.bind="{schema: schema, value: value}"
model.bind="{attribute: attribute, value: value}"
view.bind="component"></compose>

<compose
if.bind="!isHtmlComponent"
model.bind="{schema: schema, value: value}"
model.bind="{attribute: attribute, value: value}"
view-model.bind="component"></compose>

</div>
@@ -6,7 +6,7 @@ import {I18N} from 'aurelia-i18n';
@inject(Config, I18N, Element)
export class FormFieldCustomElement {

@bindable schema
@bindable attribute

@bindable({defaultBindingMode: bindingMode.twoWay})
value
@@ -21,23 +21,23 @@ export class FormFieldCustomElement {
// consider: using aurelia DOM pal
let attrsElmnt = $(this.element).find('[attrs]');
if (attrsElmnt) {
attrsElmnt.attr(this.schema.attributes || {});
attrsElmnt.attr(this.attribute.attributes || {});
}
}

@computedFrom('schema')
@computedFrom('attribute')
get label() {
let str = this.schema.label || this.schema.name;
let str = this.attribute.label || this.attribute.key;
if (this.config.translate) {
return this.i18n.tr(str);
}
return str;
}

@computedFrom('schema')
@computedFrom('attribute')
get component() {
this.schema.type = aliasOf(this.config, this.schema.type);
return component(this.config, this.schema);
this.attribute.type = aliasOf(this.config, this.attribute.type);
return component(this.config, this.attribute);
}

/**
@@ -1,9 +1,9 @@
<template>

<form-field
value.bind="model[def.name]"
schema.bind="def"
repeat.for="def of schema">
value.bind="model[attribute.key]"
attribute.bind="attribute"
repeat.for="attribute of schema">
</form-field>

</template>
@@ -4,8 +4,8 @@
<input
attrs
type="checkbox"
name.bind="schema.name"
checked.bind="schema.value">
name.bind="attribute.key"
checked.bind="attribute.value">
</label>
</div>
</template>
@@ -1,11 +1,11 @@
<template>

<div class="checkbox" repeat.for="option of schema.options">
<div class="checkbox" repeat.for="option of attribute.options">
<label>
<input
attrs
type="checkbox"
name.bind="schema.name"
name.bind="attribute.key"
model.bind="option.value"
checked.bind="value">
${option.name}
@@ -3,7 +3,7 @@
<fieldset attrs>
<form-fields
model.bind="value"
schema.bind="schema.schema">
schema.bind="attribute.schema">
</form-fields>
</fieldset>

@@ -2,6 +2,6 @@
<input
attrs
type="file"
name.bind="schema.name"
value.bind="schema.value">
name.bind="attribute.key"
value.bind="attribute.value">
</template>
@@ -2,7 +2,7 @@
<input
attrs
class="form-control"
type.bind="schema.type"
name.bind="schema.name"
type.bind="attribute.type"
name.bind="attribute.key"
value.bind="value">
</template>
@@ -1,11 +1,11 @@
<template>

<div class="radio" repeat.for="option of schema.options">
<div class="radio" repeat.for="option of attribute.options">
<label>
<input
attrs
type="radio"
name.bind="schema.name"
name.bind="attribute.key"
model.bind="option.value"
checked.bind="value">
${option.name}
@@ -1,6 +1,6 @@
<template>
<select attrs value.bind="value" class="form-control">
<option selected disabled value="-1"></option>
<option repeat.for="option of schema.options" model.bind="option.value">${option.name}</option>
<option repeat.for="option of attribute.options" model.bind="option.value">${option.name}</option>
</select>
</template>
@@ -2,7 +2,7 @@
<input
attrs
class="pull-right btn btn-primary"
type.bind="schema.type"
name.bind="schema.name"
value.bind="schema.name">
type.bind="attribute.type"
name.bind="attribute.key"
value.bind="attribute.key">
</template>
@@ -2,6 +2,6 @@
<textarea
attrs
class="form-control"
name.bind="schema.name"
name.bind="attribute.key"
value.bind="value"></textarea>
</template>

0 comments on commit b2987c9

Please sign in to comment.