Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
136 changes: 63 additions & 73 deletions common/config/rush/npm-shrinkwrap.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions packages/react-forms-dom/src/components/submit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,21 @@ export class Submit extends BaseFormButton<SubmitProps, BaseFormButtonStateRecor
disableOnError: true
};

protected OnButtonClick: React.MouseEventHandler<HTMLButtonElement> = event => {
// If Button is outside of Form context, initiate form submit.
if (this.props.formId !== null) {
this.FormStore.InitiateFormSubmit();
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Proxy to props.onClick is missing.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch. 👏 Will fix in next PR.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in #115.

}

public render(): JSX.Element {
return <button
type="submit"
className={this.ClassName}
style={this.InlineStyles}
disabled={this.Disabled}
onClick={this.OnButtonClick}
{...this.GetHTMLProps(this.props) }
>
{this.props.children}
</button>;
Expand Down
13 changes: 11 additions & 2 deletions packages/react-forms/src/abstractions/base-container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import * as PropTypes from "prop-types";
import { FormStore } from "../stores/form-store";
import { StateChanged } from "../actions/form-store";
import { FSHContainer } from "../stores/form-stores-handler";
import { EventSubscription } from "action-emitter";

export interface BaseContainerProps {
formId?: string;
Expand All @@ -18,10 +19,12 @@ export abstract class BaseContainer<TProps extends BaseContainerProps, TState> e
public context: BaseContainerParentContext;

public static contextTypes: PropTypes.ValidationMap<BaseContainerParentContext> = {
FormId: PropTypes.string.isRequired,
FormId: PropTypes.string,
FieldId: PropTypes.string
};

private eventStoreSubscription: EventSubscription | undefined;

protected get FormId(): string {
const propFormId: string | undefined = this.props.formId;
if (propFormId != null) {
Expand Down Expand Up @@ -53,7 +56,13 @@ export abstract class BaseContainer<TProps extends BaseContainerProps, TState> e
throw new Error(`@simplr/react-forms: Container is already in a Form '${this.context.FormId}' context, ${but}.`);
}

this.FormStore.addListener(StateChanged, this.OnStoreUpdated.bind(this));
this.eventStoreSubscription = this.FormStore.addListener(StateChanged, this.OnStoreUpdated.bind(this));
}

public componentWillUnmount(): void {
if (this.eventStoreSubscription != null) {
this.eventStoreSubscription.remove();
}
}

protected abstract OnStoreUpdated(): void;
Expand Down