diff --git a/app/components/create-options-datetime.js b/app/components/create-options-datetime.js index e1d5c5325..772d88d24 100644 --- a/app/components/create-options-datetime.js +++ b/app/components/create-options-datetime.js @@ -2,7 +2,7 @@ import { inject as service } from '@ember/service'; import { readOnly, mapBy, filter } from '@ember/object/computed'; import Component from '@ember/component'; import { isPresent, isEmpty } from '@ember/utils'; -import { observer, get } from '@ember/object'; +import { action, observer, get } from '@ember/object'; import { validator, buildValidations } @@ -128,7 +128,7 @@ export default Component.extend(modelValidations, { } else { this.set('shouldShowErrors', true); } - } + }, }, // dates are sorted datesForFirstDay: readOnly('groupedDates.firstObject.items'), @@ -148,4 +148,20 @@ export default Component.extend(modelValidations, { groupedDates: groupBy('dates', raw('day')), store: service(), + + inputChanged: action(function(date, value) { + // reset partially filled state + date.set('isPartiallyFilled', false); + + date.set('time', value); + }), + + validateInput: action(function(date, event) { + let element = event.target; + + if (!element.checkValidity()) { + // partially filled time input + date.set('isPartiallyFilled', true); + } + }), }); diff --git a/app/locales/ca/translations.js b/app/locales/ca/translations.js index 57fccd430..3b5ef1863 100644 --- a/app/locales/ca/translations.js +++ b/app/locales/ca/translations.js @@ -148,6 +148,7 @@ export default { phone: '{{description}} ha de ser un número de telèfon vàlid', url: '{{description}} ha de ser un URL vàlid ', time: '{{description}} ha de ser un orari vàlid (p. ex. 10:45)', + 'time.notPartially': 'Partially times are not supported', unique: '{{description}} ha de ser explícita', 'unique.name': 'Aquest nom ja s\'ha usat' } diff --git a/app/locales/de/translations.js b/app/locales/de/translations.js index 15743c2f3..9043a532b 100644 --- a/app/locales/de/translations.js +++ b/app/locales/de/translations.js @@ -148,6 +148,7 @@ export default { phone: '{{description}} muss eine gültige Telefonnummer sein', url: '{{description}} muss eine gültige URL sein', time: '{{description}} muss eine gültige Zeit sein (z.B. 10:45)', + 'time.notPartially': 'Zeiten müssen vollständig sein', unique: '{{description}} müssen eindeutig sein', 'unique.name': 'Dieser Name wurde bereits genutzt' } diff --git a/app/locales/en/translations.js b/app/locales/en/translations.js index cb2600b8d..ca26cd01a 100644 --- a/app/locales/en/translations.js +++ b/app/locales/en/translations.js @@ -148,6 +148,7 @@ export default { phone: '{{description}} must be a valid phone number', url: '{{description}} must be a valid URL ', time: '{{description}} must be a valid time (e.g. 10:45)', + 'time.notPartially': 'Partially times are not supported', unique: '{{description}} must be explicit', 'unique.name': 'This name has already been used' } diff --git a/app/locales/es/translations.js b/app/locales/es/translations.js index 188328a84..034702a29 100644 --- a/app/locales/es/translations.js +++ b/app/locales/es/translations.js @@ -148,6 +148,7 @@ export default { phone: '{{description}} debe de ser un número de teléfono valido', url: '{{description}} debe de ser una URL valida', time: '{{description}} debe de ser un horario valido (p.ej. 10:45)', + 'time.notPartially': 'Partially times are not supported', unique: '{{description}} debe de ser único', 'unique.name': 'Este nombre ya está usado' } diff --git a/app/locales/it/translations.js b/app/locales/it/translations.js index 29f924bc0..ccf322d82 100644 --- a/app/locales/it/translations.js +++ b/app/locales/it/translations.js @@ -148,6 +148,7 @@ export default { phone: '{{description}} deve essere un numero di telefono valido.', url: '{{description}} deve essere un URL valido ', time: '{{description}} deve essere un orario valido (ad es. 10:45)', + 'time.notPartially': 'Partially times are not supported', unique: '{{description}} deve essere esplicito', 'unique.name': 'Questo nome è già stato usato' } diff --git a/app/models/option.js b/app/models/option.js index cc4fe91bf..169fee931 100644 --- a/app/models/option.js +++ b/app/models/option.js @@ -15,6 +15,10 @@ from 'ember-cp-validations'; const { attr } = DS; const Validations = buildValidations({ + isPartiallyFilled: validator('falsy', { + messageKey: 'errors.time.notPartially', + dependentKeys: ['model.i18n.locale'], + }), title: [ validator('iso8601', { active: readOnly('model.poll.isFindADate'), @@ -48,7 +52,11 @@ const Validations = buildValidations({ validator('alias', { alias: 'title', firstMessageOnly: true - }) + }), + // alias is partially filled validation as that's part of time validation + validator('alias', { + alias: 'isPartiallyFilled', + }), ] }); @@ -114,6 +122,12 @@ export default Fragment.extend(Validations, { this.title.length === 'YYYY-MM-DDTHH:mm:ss.SSSZ'.length; }), + // isPartiallyFilled should be set only for times on creation if input is filled + // partially (e.g. "11:--"). It's required cause ember-cp-validations does not + // provide any method to push a validation error into validations. It's only + // working based on a property of the model. + isPartiallyFilled: false, + time: computed('date', { get() { const date = this.date; @@ -130,7 +144,7 @@ export default Fragment.extend(Validations, { return date.format('HH:mm'); }, set(key, value) { - const date = this.date; + let date = this.date; assert( 'can not set a time if current value is not a valid date', moment.isMoment(date) diff --git a/app/templates/components/create-options-datetime.hbs b/app/templates/components/create-options-datetime.hbs index 2c1b7f28c..615a3a805 100644 --- a/app/templates/components/create-options-datetime.hbs +++ b/app/templates/components/create-options-datetime.hbs @@ -43,10 +43,13 @@