Skip to content

Commit 7e705da

Browse files
committed
Fixed bug that data form following steps dont aplies. Added requestContentType attribute to save method
1 parent 9e28d4d commit 7e705da

File tree

8 files changed

+37
-12
lines changed

8 files changed

+37
-12
lines changed

README.md

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,4 +82,20 @@ http://localhost:8000/demo/wizardConfig.js when server is started.
8282
When user clicks "save" button, it gets disabled and text is changed to message indicating that save opertion is in process. There is default message, but if you want to customize it, you can set '**messageWhenSaving**' in step config.
8383
Look at http://localhost:8000/demo/wizardConfig.js when server is started to see such sample configuration, and point to
8484
http://localhost:8000/?descriptor=demo/wizardConfig.js
85-
to see working example (when saving first step, there is delay of 1 second on server in order to demonstrate saving message behaviour.)
85+
to see working example (when saving first step, there is delay of 1 second on server in order to demonstrate saving message behaviour.)
86+
87+
##Saving data
88+
How to save data is described in "save" attribute of step config. See demo/wizardConfig.js for reference. Following attributes are accepted:
89+
..- __method__ ("GET" | "POST" | "DELETE" | "PUT" etc) default GET
90+
..- __url__ , where to save data (ex: /my/awesome/script)
91+
..- __requestContentType__ ("application/json; charset=utf-8" | "application/x-www-form-urlencoded; charset=UTF-8") default json
92+
example
93+
```json
94+
save : {
95+
method: "POST",
96+
url: "/save/step1",
97+
requestContentType: "application/json; charset=utf-8"
98+
// requestContentType: "application/x-www-form-urlencoded; charset=UTF-8"
99+
}
100+
```
101+

demo/step1save.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ var response = {
66
next : {
77
title : "Verifikacija pin-a",
88
description: "Kako bi omogućili pristup, na vaš broj telefona poslan vam je pin. Molim da ga ovdje unesete.",
9-
data : {},
9+
data : {
10+
pin: "12345"
11+
},
1012
formConfig : {
1113
model : t.struct({
1214
pin: t.Str

demo/wizardConfig.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,9 @@
5959
},
6060
save : {
6161
method: "POST",
62-
url: "/save/step1"
62+
url: "/save/step1",
63+
requestContentType: "application/json; charset=utf-8"
64+
// requestContentType: "application/x-www-form-urlencoded; charset=UTF-8"
6365
},
6466
messageWhenSaving: "Spremam vaše osobne podatke..."
6567
}

dist/demo.dev.js

Lines changed: 5 additions & 4 deletions
Large diffs are not rendered by default.

lib/wizardStep.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ WizardStep.propTypes = {
100100
buttonLabel: React.PropTypes.string,
101101
title: React.PropTypes.string,
102102
description: React.PropTypes.string,
103-
saving: React.PropTypes.boolean,
103+
saving: React.PropTypes.bool,
104104
savingButtonLabel: React.PropTypes.string,
105105
}
106106

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "generic-form-ui",
3-
"version": "1.2.0",
3+
"version": "1.3.0",
44
"description": "Library for creating UI for generic form models",
55
"main": "ui-form-controller.js",
66
"repository": {

ui-form-controller.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,8 @@ class UiFormController extends Component{
131131
console.log("invoked save script: " + save.url + " and got result: ");
132132
console.log(data);
133133
this.processResponse(data);
134-
}, (errorMessage)=>this.setState({errorMessage: errorMessage}), save.method, JSON.stringify(value), "text");
134+
}, (errorMessage)=>this.setState({errorMessage: errorMessage}), save.method,
135+
JSON.stringify(value), "text", save.requestContentType);
135136
}
136137

137138
/**
@@ -145,10 +146,11 @@ class UiFormController extends Component{
145146
console.warn("status field is not defined in response! Finishing the wizard by convention.");
146147
status = "0";
147148
}
149+
let stateStep = jQuery.isEmptyObject(descriptor.validationErrors)?descriptor.next:this.state.currentStep;
148150
let nextState = {responseStatus: status,
149151
message: descriptor.message,
150152
validationErrors: descriptor.validationErrors,
151-
value: this.state.value,
153+
value: (stateStep)?stateStep.data:this.state.value,//this.state.value,
152154
currentStep: jQuery.isEmptyObject(descriptor.validationErrors)?descriptor.next:this.state.currentStep,
153155
saving: false
154156
};

views/step1saveResponse.ejs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ var response = {
77
next : {
88
title : "Verifikacija pin-a",
99
description: "Kako bi omogućili pristup, na vaš broj telefona poslan vam je pin. Molim da ga ovdje unesete.",
10-
data : {},
10+
data : {
11+
pin: "1234"
12+
},
1113
formConfig : {
1214
model : t.struct({
1315
pin: t.Str

0 commit comments

Comments
 (0)