@@ -5,14 +5,6 @@ import { BaseContainer, BaseContainerProps } from "simplr-forms-core";
5
5
import { FormError } from "simplr-forms-core/contracts" ;
6
6
7
7
export interface SubmitProps extends BaseContainerProps , React . HTMLProps < HTMLButtonElement > {
8
- /**
9
- * Disable when form is submitting.
10
- *
11
- * Default: false
12
- * @type {boolean }
13
- * @memberOf SubmitProps
14
- */
15
- disableOnSubmitting ?: boolean ;
16
8
/**
17
9
* Disable when at least one field has error.
18
10
*
@@ -28,7 +20,7 @@ export interface SubmitProps extends BaseContainerProps, React.HTMLProps<HTMLBut
28
20
* @type {boolean }
29
21
* @memberOf SubmitProps
30
22
*/
31
- disableOnWaiting ?: boolean ;
23
+ disableOnBusy ?: boolean ;
32
24
/**
33
25
* Disable when all fields are pristine.
34
26
*
@@ -37,7 +29,8 @@ export interface SubmitProps extends BaseContainerProps, React.HTMLProps<HTMLBut
37
29
* @memberOf SubmitProps
38
30
*/
39
31
disableOnPristine ?: boolean ;
40
- waiting ?: boolean ;
32
+ busy ?: boolean ;
33
+ busyClass ?: string ;
41
34
}
42
35
43
36
export interface SubmitState {
@@ -50,6 +43,13 @@ export interface SubmitState {
50
43
export interface SubmitStateRecord extends TypedRecord < SubmitStateRecord > , SubmitState { }
51
44
52
45
export class Submit extends BaseContainer < SubmitProps , SubmitStateRecord > {
46
+ public static defaultProps : SubmitProps = {
47
+ disableOnBusy : true ,
48
+ disableOnError : true ,
49
+ disableOnPristine : false ,
50
+ busyClass : "busy"
51
+ } ;
52
+
53
53
protected OnStoreUpdated ( ) : void {
54
54
const formStore = this . FormStore . GetState ( ) ;
55
55
const newState = {
@@ -62,7 +62,8 @@ export class Submit extends BaseContainer<SubmitProps, SubmitStateRecord> {
62
62
const newStateRecord = recordify ( newState ) ;
63
63
if ( ! newStateRecord . equals ( this . state ) ) {
64
64
this . setState ( ( prevState ) => {
65
- // TODO: newStateRecord becomes an empty object after setState
65
+ // newStateRecord becomes an empty object after setState
66
+ // This happens because of an underlying Immutable.Record
66
67
return newState ;
67
68
} ) ;
68
69
}
@@ -79,28 +80,47 @@ export class Submit extends BaseContainer<SubmitProps, SubmitStateRecord> {
79
80
return true ;
80
81
}
81
82
82
- // TODO: waiting/busy
83
-
84
- if ( this . props . disableOnSubmitting === true &&
85
- this . state . Submitting === true ) {
86
- console . log ( "Disabling submit on submitting." ) ;
83
+ if ( this . props . disableOnBusy === true &&
84
+ this . Busy ) {
85
+ console . log ( "Disabling submit on busy." ) ;
87
86
return true ;
88
87
}
89
88
90
89
if ( this . props . disableOnPristine === true &&
91
90
this . state . Pristine === true ) {
92
- console . log ( "Disabling submit on pristine." ) ;
93
91
return true ;
94
92
}
95
93
}
96
94
97
95
return false ;
98
96
}
99
97
98
+ protected get Busy ( ) : boolean {
99
+ return this . props . busy === true ||
100
+ this . state != null &&
101
+ ( this . state . Validating ||
102
+ this . state . Submitting ) ;
103
+ }
104
+
105
+ protected get InlineStyles ( ) {
106
+ let inlineStyles : React . CSSProperties = { } ;
107
+
108
+ if ( this . props . style != null ) {
109
+ inlineStyles = this . props . style ;
110
+ }
111
+
112
+ if ( this . Busy && ! this . props . disabled ) {
113
+ inlineStyles . cursor = this . props . busyClass ;
114
+ }
115
+
116
+ return inlineStyles ;
117
+ }
118
+
100
119
render ( ) {
101
120
return < button
102
121
type = "submit"
103
122
disabled = { this . Disabled }
123
+ style = { this . InlineStyles }
104
124
>
105
125
{ this . props . children }
106
126
</ button > ;
0 commit comments