aurelia-form
Version:
Makes working with forms just a tad more pleasant.
54 lines (36 loc) • 1.12 kB
JavaScript
import {bindable, customElement, bindingMode, computedFrom} from 'aurelia-framework';
import {resolvedView} from 'aurelia-view-manager';
export class FormSelect {
value;
name = '';
classes = '';
readonly = false;
disabled = false;
multiple = false;
selectOptions = [];
options = {};
optionLabel = 'name';
autofocus;
required;
translate = true;
get optionLabels() {
return this.selectOptions.map(option => {
if (typeof option !== 'object') {
return {value: option, label: option};
}
if (this.optionLabel) {
option.label = option[this.optionLabel] || '';
}
return option;
});
}
getOptionLabel(option) {
if (typeof option === 'object' && this.optionLabel) {
return option[this.optionLabel] || option;
}
return option;
}
}