Skip to content
This repository has been archived by the owner on Nov 25, 2020. It is now read-only.

Commit

Permalink
feat(project): add select
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremyvergnas committed Feb 17, 2017
1 parent 298338a commit 0a9c051
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 4 deletions.
6 changes: 4 additions & 2 deletions src/aurelia-form.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ export function configure(aurelia, config) {
let defaultElements = [
'input',
'checkbox',
'radio'
'radio',
'select'
];

aurelia.globalResources(
Expand Down Expand Up @@ -52,7 +53,8 @@ export const config = {
float : 'input',
bool : 'checkbox',
boolean: 'checkbox',
text : 'input'
text : 'input',
select : 'select'
}
}
};
24 changes: 22 additions & 2 deletions src/component/form-element.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,14 @@ export class FormElement {
@bindable disabled = false;
@bindable multiple = false;
@bindable options = {};
@bindable selectOptions = [];
@bindable optionLabel;
proxyAttributes = [
'value',
'name',
Expand All @@ -36,7 +42,10 @@ export class FormElement {
'readonly',
'disabled',
'options',
'type'
'type',
'multiple',
'selectOptions',
'optionLabel'
];
constructor(config, DOMElement, templatingEngine) {
Expand All @@ -54,7 +63,11 @@ export class FormElement {
}
setAttributes(DOMElement) {
this.proxyAttributes.forEach(attribute => DOMElement.setAttribute(`${attribute}.bind`, attribute));
this.proxyAttributes.forEach(attribute => {
let formattedAttribute = styleHyphenFormat(attribute);
DOMElement.setAttribute(`${formattedAttribute}.bind`, attribute)
});
}
getElementName() {
Expand All @@ -71,3 +84,10 @@ export class FormElement {
return elementName;
}
}
function styleHyphenFormat(propertyName) {
function upperToHyphenLower(match, offset) {
return (offset ? '-' : '') + match.toLowerCase();
}
return propertyName.replace(/[A-Z]/g, upperToHyphenLower);
}
10 changes: 10 additions & 0 deletions src/component/form-group.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,16 @@ export class FormGroup {

@bindable behavior;

@bindable readonly = false;

@bindable disabled = false;

@bindable multiple = false;

@bindable selectOptions = [];

@bindable optionLabel;

is(oneOf, then, source) {
if (typeof oneOf === 'string') {
oneOf = oneOf.split(',').map(one => one.trim());
Expand Down
32 changes: 32 additions & 0 deletions src/component/form-select.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import {bindable, customElement, bindingMode} from 'aurelia-framework';
import {resolvedView} from 'aurelia-view-manager';

@resolvedView('spoonx/form', 'form-select')
@customElement('form-select')
export class FormSelect {
@bindable({defaultBindingMode: bindingMode.twoWay}) value;

@bindable name = '';
@bindable classes = '';
@bindable readonly = false;
@bindable disabled = false;
@bindable multiple = false;
@bindable selectOptions = [];
@bindable options = {};
@bindable optionLabel = 'name';
getOptionLabel(option) {
if (typeof option === 'object' && this.optionLabel) {
return option[this.optionLabel] || option;
}

return option;
}
}
5 changes: 5 additions & 0 deletions src/component/view/bootstrap/form-group.html
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@
element.bind="element"
type.bind="type"
value.bind="value"
readonly.bind="readonly"
disabled.bind="disabled"
multiple.bind="multiple"
select-options.bind="selectOptions"
option-label.bind="optionLabel"
></form-element>
</slot>

Expand Down
13 changes: 13 additions & 0 deletions src/component/view/bootstrap/form-select.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<template>
<select
value.bind="value"
class="form-control ${classes}"
name.bind="name"
readonly.bind="readonly !== false"
prefixed="options.bind: options; prefix: input-"
disabled.bind="disabled !== false"
multiple.bind="multiple !== false"
>
<option repeat.for="option of selectOptions" model.bind="option" t="${getOptionLabel(option)}">${getOptionLabel(option)}</option>
</select>
</template>

0 comments on commit 0a9c051

Please sign in to comment.