submits only visible items
This commit is contained in:
@@ -6,9 +6,10 @@ import {FormControl, FormGroup} from '@angular/forms';
|
||||
selector: 'dyn-form',
|
||||
template: `
|
||||
<form (ngSubmit)="submit()" [formGroup]="form">
|
||||
<dyn-question *ngFor="let question of questions"
|
||||
[hidden]="question.properties.methods && question.properties.methods.indexOf(type)==-1 || question.properties.spezialization && form.value.type!=question.properties.spezialization" [ngSwitch]="question.type"
|
||||
<div *ngFor="let question of questions">
|
||||
<dyn-question *ngIf="!(question.properties.methods && question.properties.methods.indexOf(type)==-1 || question.properties.spezialization && form.value.type!=question.properties.spezialization)" [ngSwitch]="question.type"
|
||||
[question]="question" [form]="form" [type]="type" (onChange)="valueChange.emit(form.value)"></dyn-question>
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<button [disabled]="form.invalid" type="submit">Save</button>
|
||||
</div>
|
||||
@@ -40,7 +41,18 @@ export class DynFormComponent implements OnChanges {
|
||||
}
|
||||
|
||||
private submit() {
|
||||
if (this.form.valid)
|
||||
this.onSubmit.emit(this.form.value);
|
||||
if (this.form.valid) {
|
||||
let vals = {};
|
||||
let type: string = this.form.value.type;
|
||||
for (let question of this.questions) {
|
||||
let specType = question.properties.spezialization;
|
||||
let methods = question.properties.methods;
|
||||
let key = question.properties.key;
|
||||
if (!(methods && methods.indexOf(this.type)==-1 || specType && type!=specType)) {
|
||||
vals[key] = this.form.value[key];
|
||||
}
|
||||
}
|
||||
this.onSubmit.emit(vals);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ export class QuestionService {
|
||||
type: 'dropdown',
|
||||
description: 'Cool dropdown',
|
||||
properties: {
|
||||
key: 'cooldrop',
|
||||
key: 'type',
|
||||
label: 'Dropdown',
|
||||
order: 2,
|
||||
methods: ['insert'],
|
||||
@@ -51,7 +51,8 @@ export class QuestionService {
|
||||
properties: {
|
||||
key: 'textarea',
|
||||
label: 'Textareaaaa',
|
||||
order: 4
|
||||
order: 4,
|
||||
spezialization: 'world'
|
||||
}, constraints: {
|
||||
optional: false
|
||||
}
|
||||
@@ -59,7 +60,7 @@ export class QuestionService {
|
||||
]), null), 10);
|
||||
}
|
||||
|
||||
private static orderItems(list: Array <any>) {
|
||||
private static orderItems(list: QuestionInterface[]): QuestionInterface[] {
|
||||
function compare(a: any, b: any) {
|
||||
if (a.properties.order < b.properties.order)
|
||||
return -1;
|
||||
|
||||
Reference in New Issue
Block a user