decide.nolog.cz/app/components/create-options.js

41 lines
1 KiB
JavaScript
Raw Normal View History

import Ember from 'ember';
import {
validator, buildValidations
}
from 'ember-cp-validations';
let Validations = buildValidations({
options: [
validator('collection', true),
validator('length', {
2016-05-21 17:17:08 +02:00
dependentKeys: ['options.[]', 'i18n.locale'],
min: 1,
message() {
const i18n = this.model.get('i18n');
const isFindADate = this.model.get('isFindADate');
const translationKey = isFindADate ? 'create.options.error.notEnoughDates' : 'create.options.error.notEnoughOptions';
const message = i18n.t(translationKey);
return message.toString();
}
}),
validator('valid-collection', {
dependentKeys: ['options.[]', 'options.@each.title']
})
]
});
export default Ember.Component.extend(Validations, {
actions: {
2016-01-28 22:49:14 +01:00
submit() {
if (this.get('validations.isValid')) {
this.sendAction('nextPage');
2016-02-08 23:46:30 +01:00
} else {
this.set('shouldShowErrors', true);
}
}
2016-02-08 23:46:30 +01:00
},
2016-05-21 17:17:08 +02:00
// consumed by validator
i18n: Ember.inject.service(),
2016-02-08 23:46:30 +01:00
shouldShowErrors: false
});