Skip to content

Commit 8676504

Browse files
Form submitting.
1 parent a7a1f84 commit 8676504

File tree

7 files changed

+115
-82
lines changed

7 files changed

+115
-82
lines changed
Lines changed: 72 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -1,72 +1,72 @@
1-
{
2-
"name": "simplr-forms-core",
3-
"version": "4.0.0-pre-alpha.10",
4-
"description": "Shared simplr-forms logic.",
5-
"repository": "SimplrJS/simplr-forms",
6-
"homepage": "https://github.com/SimplrJS/simplr-forms",
7-
"main": "main.js",
8-
"types": "index.d.ts",
9-
"author": "simplrjs <[email protected]> (https://github.com/simplrjs)",
10-
"scripts": {
11-
"build": "webpack && npm run tslint",
12-
"watch": "webpack -w",
13-
"tslint": "tslint --config ./tslint.json --project . --exclude __tests__/**/* && echo TsLint test successfully passed.",
14-
"uglifyjs": "uglifyjs ./dist/simplr-forms-core.js -o ./dist/simplr-forms-core.min.js --compress --mangle",
15-
"release": "npm run build && npm run uglifyjs",
16-
"test": "jest",
17-
"test-watch": "jest --watchAll",
18-
"test-coverage": "npm test -- --coverage"
19-
},
20-
"license": "AGPL-3.0",
21-
"files": [
22-
"dist",
23-
"@types",
24-
"**/*.md",
25-
"*.js",
26-
"!*.config.js"
27-
],
28-
"devDependencies": {
29-
"@types/enzyme": "^2.7.9",
30-
"@types/jest": "^19.2.2",
31-
"@types/prop-types": "^15.5.1",
32-
"@types/sinon": "^2.1.2",
33-
"enzyme": "^2.8.2",
34-
"jest": "^19.0.2",
35-
"jest-enzyme": "^3.0.1",
36-
"on-build-webpack": "^0.1.0",
37-
"react-dom": "^15.5.4",
38-
"react-test-renderer": "^15.5.4",
39-
"sinon": "^2.1.0",
40-
"ts-jest": "^19.0.10",
41-
"ts-loader": "^2.0.3",
42-
"tslint": "^5.1.0",
43-
"typescript": "2.3.0",
44-
"uglify-js": "^2.8.22",
45-
"webpack": "^2.4.1"
46-
},
47-
"dependencies": {
48-
"@types/fbemitter": "^2.0.32",
49-
"@types/flux": "^3.0.1",
50-
"@types/react": "^15.0.22",
51-
"@types/react-dom": "^15.5.0",
52-
"action-emitter": "^0.2.1",
53-
"fbemitter": "^2.1.1",
54-
"immutable": "^3.8.1",
55-
"prop-types": "^15.5.8",
56-
"react": "15.5.4",
57-
"react-dom": "^15.5.4",
58-
"typed-immutable-record": "^0.0.6"
59-
},
60-
"jest": {
61-
"setupTestFrameworkScriptFile": "./node_modules/jest-enzyme/lib/index.js",
62-
"transform": {
63-
".(ts|tsx)": "<rootDir>/node_modules/ts-jest/preprocessor.js"
64-
},
65-
"testRegex": "/__tests__/.*\\.(test|spec).(ts|tsx|js)$",
66-
"moduleFileExtensions": [
67-
"ts",
68-
"tsx",
69-
"js"
70-
]
71-
}
72-
}
1+
{
2+
"name": "simplr-forms-core",
3+
"version": "4.0.0-pre-alpha.18",
4+
"description": "Shared simplr-forms logic.",
5+
"repository": "SimplrJS/simplr-forms",
6+
"homepage": "https://github.com/SimplrJS/simplr-forms",
7+
"main": "main.js",
8+
"types": "index.d.ts",
9+
"author": "simplrjs <[email protected]> (https://github.com/simplrjs)",
10+
"scripts": {
11+
"build": "webpack && npm run tslint",
12+
"watch": "webpack -w",
13+
"tslint": "tslint --config ./tslint.json --project . --exclude __tests__/**/* && echo TsLint test successfully passed.",
14+
"uglifyjs": "uglifyjs ./dist/simplr-forms-core.js -o ./dist/simplr-forms-core.min.js --compress --mangle",
15+
"release": "npm run build && npm run uglifyjs",
16+
"test": "jest",
17+
"test-watch": "jest --watchAll",
18+
"test-coverage": "npm test -- --coverage"
19+
},
20+
"license": "AGPL-3.0",
21+
"files": [
22+
"!node_modules",
23+
"**/*.md",
24+
"*.js",
25+
"**/*.d.ts",
26+
"!*.config.js"
27+
],
28+
"devDependencies": {
29+
"@types/enzyme": "^2.7.9",
30+
"@types/jest": "^19.2.2",
31+
"@types/sinon": "^2.1.2",
32+
"enzyme": "^2.8.2",
33+
"jest": "^19.0.2",
34+
"jest-enzyme": "^3.0.1",
35+
"on-build-webpack": "^0.1.0",
36+
"react-dom": "^15.5.4",
37+
"react-test-renderer": "^15.5.4",
38+
"sinon": "^2.1.0",
39+
"ts-jest": "^19.0.10",
40+
"ts-loader": "^2.0.3",
41+
"tslint": "^5.1.0",
42+
"typescript": "2.3.0",
43+
"uglify-js": "^2.8.22",
44+
"webpack": "^2.4.1"
45+
},
46+
"dependencies": {
47+
"@types/fbemitter": "^2.0.32",
48+
"@types/flux": "^3.0.1",
49+
"@types/prop-types": "^15.5.1",
50+
"@types/react": "^15.0.22",
51+
"@types/react-dom": "^15.5.0",
52+
"action-emitter": "^0.2.1",
53+
"fbemitter": "^2.1.1",
54+
"immutable": "^3.8.1",
55+
"prop-types": "^15.5.8",
56+
"react": "15.5.4",
57+
"react-dom": "^15.5.4",
58+
"typed-immutable-record": "^0.0.6"
59+
},
60+
"jest": {
61+
"setupTestFrameworkScriptFile": "./node_modules/jest-enzyme/lib/index.js",
62+
"transform": {
63+
".(ts|tsx)": "<rootDir>/node_modules/ts-jest/preprocessor.js"
64+
},
65+
"testRegex": "/__tests__/.*\\.(test|spec).(ts|tsx|js)$",
66+
"moduleFileExtensions": [
67+
"ts",
68+
"tsx",
69+
"js"
70+
]
71+
}
72+
}

packages/simplr-forms-core/src/abstractions/base-container.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { StateUpdated } from "../actions/form-store";
66
import { FSHContainer } from "../stores/form-stores-handler";
77

88
export interface BaseContainerProps {
9-
formId: string;
9+
formId?: string;
1010
}
1111

1212
export interface BaseContainerParentContext {
@@ -21,8 +21,9 @@ export abstract class BaseContainer<TProps extends BaseContainerProps, TState> e
2121
};
2222

2323
protected get FormId(): string {
24-
if (this.props.formId == null) {
25-
return this.props.formId;
24+
const propFormId: string | undefined = this.props.formId;
25+
if (propFormId != null) {
26+
return propFormId;
2627
}
2728
if (this.context.FormId != null) {
2829
return this.context.FormId;

packages/simplr-forms-core/src/abstractions/base-form.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ export abstract class BaseForm<TProps extends FormContracts.FormProps, TState> e
5858
resolve(result);
5959
});
6060
}
61+
await this.FormStore.Submit(promise);
6162
}
6263

6364
componentWillUnmount() {

packages/simplr-forms-core/src/stores/form-store.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,35 @@ export class FormStore extends ActionEmitter {
212212
this.State.Form.SubmitCallback();
213213
}
214214

215+
public async Submit(promise: Promise<void>) {
216+
// Form.Submitting -> true
217+
this.State = this.State.withMutations(state => {
218+
state.Form = state.Form.merge({
219+
Submitting: true
220+
} as FormState);
221+
});
222+
223+
// Try submitting
224+
try {
225+
await promise;
226+
// No error and submitting -> false
227+
this.State = this.State.withMutations(state => {
228+
state.Form = state.Form.merge({
229+
Submitting: false,
230+
Error: undefined
231+
} as FormState);
232+
});
233+
} catch (err) {
234+
// Error and submitting -> false
235+
this.State = this.State.withMutations(state => {
236+
state.Form = state.Form.merge({
237+
Submitting: false,
238+
Error: err
239+
} as FormState);
240+
});
241+
}
242+
}
243+
215244
/**
216245
* ========================
217246
* Local helper methods

packages/simplr-forms-dom/package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "simplr-forms-dom",
3-
"version": "4.0.0-pre-alpha.13",
3+
"version": "4.0.0-pre-alpha.18",
44
"description": "DOM components for simplr-forms.",
55
"repository": "SimplrJS/simplr-forms",
66
"homepage": "https://github.com/SimplrJS/simplr-forms",
@@ -16,14 +16,14 @@
1616
"test": "jest",
1717
"test-watch": "jest --watchAll",
1818
"test-coverage": "npm test -- --coverage",
19-
"prepublishOnly": "npm run build && node ../simplr-forms-publish/dist/cli.js --from dist --to .",
20-
"postpublish": "git clean -fd"
19+
"prepublishOnly": "npm run build"
2120
},
2221
"license": "AGPL-3.0",
2322
"files": [
23+
"!node_modules",
2424
"**/*.md",
2525
"*.js",
26-
"*.d.ts",
26+
"**/*.d.ts",
2727
"!*.config.js"
2828
],
2929
"devDependencies": {
@@ -51,7 +51,7 @@
5151
"immutable": "^3.8.1",
5252
"prop-types": "^15.5.8",
5353
"react": "^15.5.4",
54-
"simplr-forms-core": "^4.0.0-pre-alpha.11",
54+
"simplr-forms-core": "^4.0.0-pre-alpha.18",
5555
"typed-immutable-record": "0.0.6"
5656
},
5757
"jest": {
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
export * from "./components/form";
22
export * from "./components/text";
3+
export * from "./components/submit";

packages/simplr-validation/__tests__/subscribers/form-store-subscriber.test.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,9 @@ describe("FormStoreSubscriber", () => {
5252

5353
formSubscriber.RemoveFormListeners();
5454

55-
expect(formStore.listeners(Actions.PropsChanged).length).toBe(0);
56-
expect(formStore.listeners(Actions.ValueChanged).length).toBe(0);
55+
expect(formStore.listeners(FieldRegistered).length).toBe(0);
56+
expect(formStore.listeners(PropsChanged).length).toBe(0);
57+
expect(formStore.listeners(ValueChanged).length).toBe(0);
5758

5859
});
5960

0 commit comments

Comments
 (0)