Skip to content

Commit bc97bf8

Browse files
Submit button Busy, InlineStyles. Clear and Reset buttons added into dom index.ts.
1 parent 360c6d0 commit bc97bf8

File tree

2 files changed

+39
-17
lines changed

2 files changed

+39
-17
lines changed

packages/simplr-forms-dom/src/components/submit.tsx

Lines changed: 37 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,6 @@ import { BaseContainer, BaseContainerProps } from "simplr-forms-core";
55
import { FormError } from "simplr-forms-core/contracts";
66

77
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;
168
/**
179
* Disable when at least one field has error.
1810
*
@@ -28,7 +20,7 @@ export interface SubmitProps extends BaseContainerProps, React.HTMLProps<HTMLBut
2820
* @type {boolean}
2921
* @memberOf SubmitProps
3022
*/
31-
disableOnWaiting?: boolean;
23+
disableOnBusy?: boolean;
3224
/**
3325
* Disable when all fields are pristine.
3426
*
@@ -37,7 +29,8 @@ export interface SubmitProps extends BaseContainerProps, React.HTMLProps<HTMLBut
3729
* @memberOf SubmitProps
3830
*/
3931
disableOnPristine?: boolean;
40-
waiting?: boolean;
32+
busy?: boolean;
33+
busyClass?: string;
4134
}
4235

4336
export interface SubmitState {
@@ -50,6 +43,13 @@ export interface SubmitState {
5043
export interface SubmitStateRecord extends TypedRecord<SubmitStateRecord>, SubmitState { }
5144

5245
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+
5353
protected OnStoreUpdated(): void {
5454
const formStore = this.FormStore.GetState();
5555
const newState = {
@@ -62,7 +62,8 @@ export class Submit extends BaseContainer<SubmitProps, SubmitStateRecord> {
6262
const newStateRecord = recordify(newState);
6363
if (!newStateRecord.equals(this.state)) {
6464
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
6667
return newState;
6768
});
6869
}
@@ -79,28 +80,47 @@ export class Submit extends BaseContainer<SubmitProps, SubmitStateRecord> {
7980
return true;
8081
}
8182

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.");
8786
return true;
8887
}
8988

9089
if (this.props.disableOnPristine === true &&
9190
this.state.Pristine === true) {
92-
console.log("Disabling submit on pristine.");
9391
return true;
9492
}
9593
}
9694

9795
return false;
9896
}
9997

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+
100119
render() {
101120
return <button
102121
type="submit"
103122
disabled={this.Disabled}
123+
style={this.InlineStyles}
104124
>
105125
{this.props.children}
106126
</button>;
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
export * from "./components/form";
22
export * from "./components/text";
33
export * from "./components/submit";
4+
export * from "./components/reset";
5+
export * from "./components/clear";

0 commit comments

Comments
 (0)