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

42 lines
977 B
JavaScript
Raw Normal View History

import Ember from 'ember';
import {
validator, buildValidations
}
from 'ember-cp-validations';
const { Component, inject } = Ember;
let Validations = buildValidations({
options: [
validator('collection', true),
validator('length', {
2016-05-21 17:17:08 +02:00
dependentKeys: ['options.[]', 'i18n.locale'],
min: 1,
2016-06-27 13:04:20 +02:00
// it's impossible to delete all text options so this case could be ignored
// for validation error message
messageKey: 'create.options.error.notEnoughDates'
}),
validator('valid-collection', {
dependentKeys: ['options.[]', 'options.@each.title']
})
]
});
export default Component.extend(Validations, {
actions: {
back() {
this.sendAction('back');
},
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: inject.service(),
2016-02-08 23:46:30 +01:00
shouldShowErrors: false
});