submits only visible items

This commit is contained in:
Sebastian Seedorf
2017-06-06 16:18:01 +02:00
parent fc2c3f029a
commit abdcfd31d1
5 changed files with 119 additions and 105 deletions

2
.idea/modules.xml generated
View File

@@ -2,7 +2,7 @@
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/AngularCounterInput.iml" filepath="$PROJECT_DIR$/.idea/AngularCounterInput.iml" />
<module fileurl="file://$PROJECT_DIR$/.idea/AngularDynFormModule.iml" filepath="$PROJECT_DIR$/.idea/AngularDynFormModule.iml" />
</modules>
</component>
</project>

195
.idea/workspace.xml generated
View File

@@ -1,15 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ChangeListManager">
<list default="true" id="77c12afa-55f1-462c-96eb-1733ba14cab9" name="Default" comment="added validation, error messages, help tooptips, async question loading and textarea input">
<change type="NEW" beforePath="" afterPath="$PROJECT_DIR$/src/app/modules/dyn-form/inputs/textbox-input.component.ts" />
<list default="true" id="77c12afa-55f1-462c-96eb-1733ba14cab9" name="Default" comment="">
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/.idea/workspace.xml" afterPath="$PROJECT_DIR$/.idea/workspace.xml" />
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/src/app/app.component.ts" afterPath="$PROJECT_DIR$/src/app/app.component.ts" />
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/src/app/modules/dyn-form/dyn-form.component.ts" afterPath="$PROJECT_DIR$/src/app/modules/dyn-form/dyn-form.component.ts" />
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/src/app/modules/dyn-form/dyn-form.module.ts" afterPath="$PROJECT_DIR$/src/app/modules/dyn-form/dyn-form.module.ts" />
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/src/app/modules/dyn-form/dyn-question.component.ts" afterPath="$PROJECT_DIR$/src/app/modules/dyn-form/dyn-question.component.ts" />
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/src/app/modules/dyn-form/inputs/textarea-input.component.ts" afterPath="$PROJECT_DIR$/src/app/modules/dyn-form/inputs/textarea-input.component.ts" />
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/src/app/modules/dyn-form/types/question.interface.ts" afterPath="$PROJECT_DIR$/src/app/modules/dyn-form/types/question.interface.ts" />
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/src/app/modules/dyn-form/services/question.service.ts" afterPath="$PROJECT_DIR$/src/app/modules/dyn-form/services/question.service.ts" />
</list>
<ignored path="$PROJECT_DIR$/.tmp/" />
<ignored path="$PROJECT_DIR$/temp/" />
@@ -24,26 +19,27 @@
<component name="ExecutionTargetManager" SELECTED_TARGET="default_target" />
<component name="FileEditorManager">
<leaf SIDE_TABS_SIZE_LIMIT_KEY="300">
<file leaf-file-name="dyn-form.component.ts" pinned="false" current-in-tab="false">
<file leaf-file-name="dyn-form.component.ts" pinned="false" current-in-tab="true">
<entry file="file://$PROJECT_DIR$/src/app/modules/dyn-form/dyn-form.component.ts">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="357">
<caret line="30" column="53" lean-forward="false" selection-start-line="30" selection-start-column="53" selection-end-line="30" selection-end-column="53" />
<state relative-caret-position="358">
<caret line="52" column="9" lean-forward="false" selection-start-line="52" selection-start-column="9" selection-end-line="52" selection-end-column="9" />
<folding>
<element signature="e#0#95#0" expanded="true" />
<marker date="1496751936688" expanded="true" signature="315:850" ph="..." />
<marker date="1496751936688" expanded="true" signature="371:726" ph="..." />
<marker date="1496751936688" expanded="true" signature="755:838" ph="..." />
<marker date="1496758517000" expanded="true" signature="315:857" ph="..." />
<marker date="1496758517000" expanded="true" signature="364:733" ph="..." />
<marker date="1496758517000" expanded="true" signature="593:720" ph="..." />
<marker date="1496758517000" expanded="true" signature="762:845" ph="..." />
</folding>
</state>
</provider>
</entry>
</file>
<file leaf-file-name="app.component.ts" pinned="false" current-in-tab="true">
<file leaf-file-name="app.component.ts" pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/src/app/app.component.ts">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="425">
<caret line="25" column="18" lean-forward="true" selection-start-line="25" selection-start-column="18" selection-end-line="25" selection-end-column="18" />
<state relative-caret-position="238">
<caret line="14" column="19" lean-forward="false" selection-start-line="14" selection-start-column="19" selection-end-line="14" selection-end-column="19" />
<folding>
<element signature="e#0#40#0" expanded="true" />
</folding>
@@ -51,27 +47,22 @@
</provider>
</entry>
</file>
<file leaf-file-name="tag-input.component.ts" pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/src/app/modules/dyn-form/inputs/tag-input.component.ts">
<file leaf-file-name="question.service.ts" pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/src/app/modules/dyn-form/services/question.service.ts">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="17">
<caret line="29" column="10" lean-forward="false" selection-start-line="29" selection-start-column="10" selection-end-line="29" selection-end-column="10" />
<folding>
<element signature="e#0#59#0" expanded="true" />
<marker date="1496417102606" expanded="true" signature="404:466" ph="..." />
</folding>
<state relative-caret-position="168">
<caret line="62" column="26" lean-forward="false" selection-start-line="62" selection-start-column="26" selection-end-line="62" selection-end-column="26" />
<folding />
</state>
</provider>
</entry>
</file>
<file leaf-file-name="textarea-input.component.ts" pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/src/app/modules/dyn-form/inputs/textarea-input.component.ts">
<file leaf-file-name="question.interface.ts" pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/src/app/modules/dyn-form/types/question.interface.ts">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="306">
<caret line="38" column="18" lean-forward="false" selection-start-line="38" selection-start-column="18" selection-end-line="38" selection-end-column="18" />
<folding>
<marker date="1496738970411" expanded="true" signature="343:363" ph="..." />
</folding>
<state relative-caret-position="17">
<caret line="1" column="34" lean-forward="false" selection-start-line="1" selection-start-column="26" selection-end-line="1" selection-end-column="34" />
<folding />
</state>
</provider>
</entry>
@@ -80,7 +71,7 @@
<entry file="file://$PROJECT_DIR$/src/app/modules/dyn-form/inputs/textbox-input.component.ts">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="187">
<caret line="14" column="5" lean-forward="true" selection-start-line="14" selection-start-column="5" selection-end-line="14" selection-end-column="5" />
<caret line="14" column="5" lean-forward="false" selection-start-line="14" selection-start-column="5" selection-end-line="14" selection-end-column="5" />
<folding />
</state>
</provider>
@@ -101,8 +92,8 @@
<file leaf-file-name="dyn-question.component.ts" pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/src/app/modules/dyn-form/dyn-question.component.ts">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="17">
<caret line="7" column="10" lean-forward="false" selection-start-line="7" selection-start-column="10" selection-end-line="7" selection-end-column="10" />
<state relative-caret-position="136">
<caret line="11" column="10" lean-forward="false" selection-start-line="11" selection-start-column="10" selection-end-line="11" selection-end-column="10" />
<folding>
<element signature="e#0#69#0" expanded="true" />
<marker date="1496755779452" expanded="true" signature="330:2741" ph="..." />
@@ -172,16 +163,16 @@
<option value="$PROJECT_DIR$/src/app/modules/dyn-form/types/keys.pipe.ts" />
<option value="$PROJECT_DIR$/src/app/modules/dyn-form/inputs/dropdown-input.component.ts" />
<option value="$PROJECT_DIR$/src/app/modules/dyn-form/inputs/tag-input.component.ts" />
<option value="$PROJECT_DIR$/src/app/modules/dyn-form/services/question.service.ts" />
<option value="$PROJECT_DIR$/src/app/services/http-cached.service.ts" />
<option value="$PROJECT_DIR$/src/app/modules/dyn-form/services/value.service.ts" />
<option value="$PROJECT_DIR$/src/app/modules/dyn-form/inputs/textarea-input.component.ts" />
<option value="$PROJECT_DIR$/src/app/modules/dyn-form/types/question.interface.ts" />
<option value="$PROJECT_DIR$/src/app/modules/dyn-form/inputs/textbox-input.component.ts" />
<option value="$PROJECT_DIR$/src/app/modules/dyn-form/dyn-form.module.ts" />
<option value="$PROJECT_DIR$/src/app/modules/dyn-form/dyn-form.component.ts" />
<option value="$PROJECT_DIR$/src/app/modules/dyn-form/dyn-question.component.ts" />
<option value="$PROJECT_DIR$/src/app/app.component.ts" />
<option value="$PROJECT_DIR$/src/app/modules/dyn-form/services/question.service.ts" />
<option value="$PROJECT_DIR$/src/app/modules/dyn-form/dyn-form.component.ts" />
</list>
</option>
</component>
@@ -542,7 +533,7 @@
<workItem from="1496298794463" duration="23800000" />
<workItem from="1496385401533" duration="17758000" />
<workItem from="1496408793177" duration="9778000" />
<workItem from="1496731076030" duration="17567000" />
<workItem from="1496731076030" duration="19780000" />
</task>
<task id="LOCAL-00001" summary="Merging">
<created>1496129612668</created>
@@ -565,11 +556,18 @@
<option name="project" value="LOCAL" />
<updated>1496417795407</updated>
</task>
<option name="localTasksCounter" value="4" />
<task id="LOCAL-00004" summary="Specialization, Textbox">
<created>1496756710062</created>
<option name="number" value="00004" />
<option name="presentableId" value="LOCAL-00004" />
<option name="project" value="LOCAL" />
<updated>1496756710062</updated>
</task>
<option name="localTasksCounter" value="5" />
<servers />
</component>
<component name="TimeTrackingManager">
<option name="totallyTimeSpent" value="89720000" />
<option name="totallyTimeSpent" value="91933000" />
</component>
<component name="TodoView">
<todo-panel id="selected-file">
@@ -582,10 +580,9 @@
</component>
<component name="ToolWindowManager">
<frame x="-8" y="-8" width="1456" height="876" extended-state="6" />
<editor active="true" />
<layout>
<window_info id="TypeScript" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.3293011" sideWeight="0.49435824" order="11" side_tool="false" content_ui="tabs" />
<window_info id="Project" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="true" show_stripe_button="true" weight="0.25599435" sideWeight="0.5" order="0" side_tool="false" content_ui="combo" />
<window_info id="Project" active="true" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="true" show_stripe_button="true" weight="0.25599435" sideWeight="0.5" order="0" side_tool="false" content_ui="combo" />
<window_info id="TODO" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.3293011" sideWeight="0.49717912" order="6" side_tool="false" content_ui="tabs" />
<window_info id="Event Log" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.3293011" sideWeight="0.5070522" order="7" side_tool="true" content_ui="tabs" />
<window_info id="Find" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="1" side_tool="false" content_ui="tabs" />
@@ -661,7 +658,8 @@
<MESSAGE value="Merging" />
<MESSAGE value="Merging completed" />
<MESSAGE value="added validation, error messages, help tooptips, async question loading and textarea input" />
<option name="LAST_COMMIT_MESSAGE" value="added validation, error messages, help tooptips, async question loading and textarea input" />
<MESSAGE value="Specialization, Textbox" />
<option name="LAST_COMMIT_MESSAGE" value="Specialization, Textbox" />
</component>
<component name="XDebuggerManager">
<breakpoint-manager>
@@ -684,9 +682,10 @@
<caret line="24" column="46" lean-forward="false" selection-start-line="24" selection-start-column="46" selection-end-line="24" selection-end-column="46" />
<folding>
<element signature="e#0#95#0" expanded="true" />
<marker date="1496751936688" expanded="true" signature="315:850" ph="..." />
<marker date="1496751936688" expanded="true" signature="371:726" ph="..." />
<marker date="1496751936688" expanded="true" signature="755:838" ph="..." />
<marker date="1496758517000" expanded="true" signature="315:857" ph="..." />
<marker date="1496758517000" expanded="true" signature="364:733" ph="..." />
<marker date="1496758517000" expanded="true" signature="593:720" ph="..." />
<marker date="1496758517000" expanded="true" signature="762:845" ph="..." />
</folding>
</state>
</provider>
@@ -775,9 +774,10 @@
<caret line="24" column="46" lean-forward="true" selection-start-line="24" selection-start-column="46" selection-end-line="24" selection-end-column="46" />
<folding>
<element signature="e#0#95#0" expanded="true" />
<marker date="1496751936688" expanded="true" signature="315:850" ph="..." />
<marker date="1496751936688" expanded="true" signature="371:726" ph="..." />
<marker date="1496751936688" expanded="true" signature="755:838" ph="..." />
<marker date="1496758517000" expanded="true" signature="315:857" ph="..." />
<marker date="1496758517000" expanded="true" signature="364:733" ph="..." />
<marker date="1496758517000" expanded="true" signature="593:720" ph="..." />
<marker date="1496758517000" expanded="true" signature="762:845" ph="..." />
</folding>
</state>
</provider>
@@ -929,14 +929,6 @@
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/app/modules/dyn-form/services/question.service.ts">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="136">
<caret line="10" column="52" lean-forward="false" selection-start-line="10" selection-start-column="52" selection-end-line="10" selection-end-column="52" />
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/app/modules/dyn-form/types/keys.pipe.ts">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="17">
@@ -1024,14 +1016,6 @@
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/app/modules/dyn-form/types/question.interface.ts">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="17">
<caret line="1" column="34" lean-forward="false" selection-start-line="1" selection-start-column="26" selection-end-line="1" selection-end-column="34" />
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/app/modules/dyn-form/inputs/textarea-input.component.ts">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="306">
@@ -1053,19 +1037,6 @@
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/app/modules/dyn-form/dyn-form.component.ts">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="357">
<caret line="30" column="53" lean-forward="false" selection-start-line="30" selection-start-column="53" selection-end-line="30" selection-end-column="53" />
<folding>
<element signature="e#0#95#0" expanded="true" />
<marker date="1496751936688" expanded="true" signature="315:850" ph="..." />
<marker date="1496751936688" expanded="true" signature="371:726" ph="..." />
<marker date="1496751936688" expanded="true" signature="755:838" ph="..." />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/app/modules/dyn-form/services/value.service.ts">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="187">
@@ -1079,28 +1050,11 @@
<entry file="file://$PROJECT_DIR$/src/app/modules/dyn-form/inputs/textbox-input.component.ts">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="187">
<caret line="14" column="5" lean-forward="true" selection-start-line="14" selection-start-column="5" selection-end-line="14" selection-end-column="5" />
<caret line="14" column="5" lean-forward="false" selection-start-line="14" selection-start-column="5" selection-end-line="14" selection-end-column="5" />
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/app/modules/dyn-form/dyn-question.component.ts">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="17">
<caret line="7" column="10" lean-forward="false" selection-start-line="7" selection-start-column="10" selection-end-line="7" selection-end-column="10" />
<folding>
<element signature="e#0#69#0" expanded="true" />
<marker date="1496755779452" expanded="true" signature="330:2741" ph="..." />
<marker date="1496755779452" expanded="true" signature="792:1097" ph="..." />
<marker date="1496755779452" expanded="true" signature="1147:1405" ph="..." />
<marker date="1496755779452" expanded="true" signature="1459:1789" ph="..." />
<marker date="1496755779452" expanded="true" signature="1843:2109" ph="..." />
<marker date="1496755779452" expanded="true" signature="2161:2592" ph="..." />
<marker date="1496755779452" expanded="true" signature="2647:2728" ph="..." />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/main.ts">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="0">
@@ -1127,13 +1081,60 @@
</entry>
<entry file="file://$PROJECT_DIR$/src/app/app.component.ts">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="425">
<caret line="25" column="18" lean-forward="true" selection-start-line="25" selection-start-column="18" selection-end-line="25" selection-end-column="18" />
<state relative-caret-position="238">
<caret line="14" column="19" lean-forward="false" selection-start-line="14" selection-start-column="19" selection-end-line="14" selection-end-column="19" />
<folding>
<element signature="e#0#40#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/app/modules/dyn-form/services/question.service.ts">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="168">
<caret line="62" column="26" lean-forward="false" selection-start-line="62" selection-start-column="26" selection-end-line="62" selection-end-column="26" />
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/app/modules/dyn-form/types/question.interface.ts">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="17">
<caret line="1" column="34" lean-forward="false" selection-start-line="1" selection-start-column="26" selection-end-line="1" selection-end-column="34" />
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/app/modules/dyn-form/dyn-question.component.ts">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="136">
<caret line="11" column="10" lean-forward="false" selection-start-line="11" selection-start-column="10" selection-end-line="11" selection-end-column="10" />
<folding>
<element signature="e#0#69#0" expanded="true" />
<marker date="1496755779452" expanded="true" signature="330:2741" ph="..." />
<marker date="1496755779452" expanded="true" signature="792:1097" ph="..." />
<marker date="1496755779452" expanded="true" signature="1147:1405" ph="..." />
<marker date="1496755779452" expanded="true" signature="1459:1789" ph="..." />
<marker date="1496755779452" expanded="true" signature="1843:2109" ph="..." />
<marker date="1496755779452" expanded="true" signature="2161:2592" ph="..." />
<marker date="1496755779452" expanded="true" signature="2647:2728" ph="..." />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/app/modules/dyn-form/dyn-form.component.ts">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="358">
<caret line="52" column="9" lean-forward="false" selection-start-line="52" selection-start-column="9" selection-end-line="52" selection-end-column="9" />
<folding>
<element signature="e#0#95#0" expanded="true" />
<marker date="1496758517000" expanded="true" signature="315:857" ph="..." />
<marker date="1496758517000" expanded="true" signature="364:733" ph="..." />
<marker date="1496758517000" expanded="true" signature="593:720" ph="..." />
<marker date="1496758517000" expanded="true" signature="762:845" ph="..." />
</folding>
</state>
</provider>
</entry>
</component>
</project>

View File

@@ -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);
}
}
}

View File

@@ -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;