Add multiline support and some error checking

This commit is contained in:
Westly Wright 2015-10-16 09:29:08 -07:00 committed by Vincent Fiduccia
parent 8ab81d73dc
commit c8c11f4d38
2 changed files with 19 additions and 3 deletions

View File

@ -41,6 +41,11 @@ export default Ember.Component.extend(NewOrEdit, {
templateChanged: function() {
this.set('loading', true);
Ember.$.ajax(this.get('selectedTemplate'), 'GET').then((response) => {
if (response.questions) {
response.questions.forEach((item) => {
item.answer = item.default;
});
}
this.set('selectedTemplateModel', response);
this.set('loading', false);
Ember.run.later(() => {
@ -80,14 +85,21 @@ export default Ember.Component.extend(NewOrEdit, {
},
validate: function() {
var errors = [];
if (!this.get('selectedTemplateModel').name) {
if (!this.get('templateName')) {
errors.push('Name is required');
}
if (!this.get('selectedTemplateModel').description) {
if (!this.get('templateDescription')) {
errors.push('Description is required');
}
if (this.get('selectedTemplateModel.questions')) {
this.get('selectedTemplateModel.questions').forEach((item) => {
if (item.required && !item.answer){
errors.push(`${item.label} is required`);
}
});
}
if (errors.length) {
this.set('errors', errors.uniq());
return false;

View File

@ -66,6 +66,10 @@
<option value={{option}}>{{option}}</option>
{{/each}}
</select>
{{else}}
{{#if (eq question.type 'multiline')}}
{{textarea value=question.answer rows='5' class='form-control'}}
{{/if}}
{{/if}}
{{/if}}
{{/if}}