Permalink
Browse files

feat(project): convert datetime to datetime-local, add input validation

  • Loading branch information...
VMBindraban authored and doktordirk committed Nov 4, 2016
1 parent f04c9a4 commit b94d70ae2dd35cbec72ef4bebb21511a47741efe
Showing with 27 additions and 8 deletions.
  1. +4 −0 doc/Usage.md
  2. +7 −5 src/bootstrap/filter.html
  3. +16 −3 src/filter.js
@@ -17,6 +17,10 @@
### columns
An array with objects containing the `name` and `value`. If no `type` is given it will assume that the column is a `text`.

When the given `type` is a `datetime`, `datetime-local` will be used instead because `datetime` is not supported by browsers.

When the input value is invalid, for example with `datetime-local`, it will add the `has-error` class to the input. (styled default by bootstrap)

Read me about [types](http://aurelia-form.spoonx.org/types.html).

### entity
@@ -21,11 +21,13 @@

<div class="col-md-4">
<div class="input-group">
<form-field
keydown.delegate="onChange($parent.$index, $index, true) & debounce:500"
value.bind="field.data.value"
element.bind="field.value">
</form-field>
<div class="${field.data.hasError ? 'has-error' : ''}">
<form-field
keydown.delegate="onChange($parent.$index, $index, true) & debounce:500"
value.bind="field.data.value"
element.bind="field.value">
</form-field>
</div>

<div class="input-group-btn">
<button
@@ -59,7 +59,7 @@ export class Filter extends CriteriaBuilder {

//eslint-disable-next-line array-callback-return
this.fieldElement.options.map(filter => {
this.fieldTypes[filter.name] = filter.type;
this.fieldTypes[filter.name] = (filter.type === 'datetime') ? 'datetime-local' : filter.type;
});

// Do we need to set pre-defined values for the filter?
@@ -181,18 +181,31 @@ export class Filter extends CriteriaBuilder {
}

onChange(blockIndex, index, isValue) {
if (typeof this.filters[blockIndex][index].data.value !== 'undefined') {
let filterValue = this.filters[blockIndex][index].data.value;

if (isValue && (filterValue === '' || filterValue === undefined)) {
this.filters[blockIndex][index].data.hasError = true;

return;
}

this.filters[blockIndex][index].data.hasError = false;

if (typeof filterValue !== 'undefined') {
this.updateCriteria();
}

// prevent updating own `type`
if (isValue) {
return;
}

// change the input type of the `valueElement` based on the selected field
for (let field of this.columns) {
if (this.filters[blockIndex][index].data.field === field.value) {
this.filters[blockIndex][index].value.type = field.type || 'string';
let type = (field.type === 'datetime') ? 'datetime-local' : field.type;

this.filters[blockIndex][index].value.type = type || 'string';

break;
}

0 comments on commit b94d70a

Please sign in to comment.