lion/packages/input-date/src/LionInputDate.js
Thomas Allmer 396deb2e3b feat: finalize validation and adopt it everywhere
Co-authored-by: Alex Ghiu <alex.ghiu@ing.com>
Co-authored-by: Gerjan van Geest <Gerjan.van.Geest@ing.com>
Co-authored-by: Thijs Louisse <Thijs.Louisse@ing.com>
Co-authored-by: Joren Broekema <joren.broekema@ing.com>
Co-authored-by: Erik Kroes <erik.kroes@ing.com>
2019-11-18 15:30:08 +01:00

39 lines
985 B
JavaScript

import { LocalizeMixin, formatDate, parseDate } from '@lion/localize';
import { FieldCustomMixin } from '@lion/field';
import { LionInput } from '@lion/input';
import { IsDate } from '@lion/validate';
/**
* `LionInputDate` has a .modelValue of type Date. It parses, formats and validates based
* on locale.
*
* @customElement lion-input-date
* @extends {LionInput}
*/
export class LionInputDate extends FieldCustomMixin(LocalizeMixin(LionInput)) {
static get properties() {
return {
modelValue: Date,
};
}
constructor() {
super();
this.parser = (value, options) => (value === '' ? undefined : parseDate(value, options));
this.formatter = formatDate;
this.defaultValidators.push(new IsDate());
}
updated(c) {
super.updated(c);
if (c.has('locale')) {
this._calculateValues();
}
}
connectedCallback() {
// eslint-disable-next-line wc/guard-super-call
super.connectedCallback();
this.type = 'text';
}
}