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
4 changes: 2 additions & 2 deletions packages/react-forms-dom/src/abstractions/base-dom-field.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
DomComponentData,
DomFieldDetails
} from "../contracts/field";
import { FormProps } from "../contracts/form";
import { BaseFormProps } from "../contracts/form";

export type BaseDomFieldState = BaseFieldState;

Expand All @@ -31,7 +31,7 @@ export abstract class BaseDomField<TProps extends DomFieldProps, TState extends
}

protected get FieldTemplate(): DomFieldTemplateCallback | undefined {
const formProps = this.FormStore.GetState().Form.Props as FormProps;
const formProps = this.FormStore.GetState().Form.Props as BaseFormProps;
if (this.props.template != null) {
return this.props.template;
}
Expand Down
4 changes: 1 addition & 3 deletions packages/react-forms-dom/src/components/checkbox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ import { FieldOnChangeCallback } from "../contracts/field";
import {
HTMLElementProps
} from "../contracts/field";
import {
FormProps
} from "../contracts/form";
import { FormProps } from "./form";

export type CheckBoxOnChangeCallback = FieldOnChangeCallback<HTMLInputElement>;

Expand Down
8 changes: 2 additions & 6 deletions packages/react-forms-dom/src/components/email.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,8 @@ import { DomFieldProps } from "../contracts/field";

import { BaseDomField, BaseDomFieldState } from "../abstractions/base-dom-field";
import { FieldOnChangeCallback } from "../contracts/field";
import {
HTMLElementProps
} from "../contracts/field";
import {
FormProps
} from "../contracts/form";
import { HTMLElementProps } from "../contracts/field";
import { FormProps } from "./form";

export type EmailOnChangeCallback = FieldOnChangeCallback<HTMLInputElement>;

Expand Down
38 changes: 37 additions & 1 deletion packages/react-forms-dom/src/components/form.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,24 @@
import * as React from "react";
import { BaseForm } from "@simplr/react-forms";

import { FormProps } from "../contracts/form";
import {
BaseFormProps,
FormOnSubmitCallback,
FormOnSubmitInternalCallback
} from "../contracts/form";

import {
FieldOnChangeCallback,
FieldOnChangeInternalCallback,
HTMLElementProps
} from "../contracts/field";

export interface FormProps extends BaseFormProps, HTMLElementProps<HTMLFormElement> {
onSubmit?: FormOnSubmitCallback & FormOnSubmitInternalCallback;
onChange?: FieldOnChangeCallback<any> & FieldOnChangeInternalCallback;

ref?: React.Ref<Form>;
}

export class Form extends BaseForm<FormProps, {}> {
public Element: HTMLFormElement | null;
Expand Down Expand Up @@ -43,10 +60,29 @@ export class Form extends BaseForm<FormProps, {}> {
this.FormStore.SubmitForm(result);
}

protected GetHTMLProps(props: BaseFormProps): {} {
const {
formId,
preventSubmitDefaultAndPropagation,
template,
formStore,
destroyOnUnmount,
forceSubmit,
disabled,
fieldsValidationType,
formValidationType,
onMount,
...restProps
} = props;

return restProps;
}

public render(): JSX.Element {
return <form
ref={this.SetElementRef}
onSubmit={this.FormSubmitHandler}
{...this.GetHTMLProps(this.props) }
>
{this.props.children}
</form>;
Expand Down
8 changes: 2 additions & 6 deletions packages/react-forms-dom/src/components/number.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,8 @@ import { DomFieldProps } from "../contracts/field";

import { BaseDomField, BaseDomFieldState } from "../abstractions/base-dom-field";
import { FieldOnChangeCallback } from "../contracts/field";
import {
HTMLElementProps
} from "../contracts/field";
import {
FormProps
} from "../contracts/form";
import { HTMLElementProps } from "../contracts/field";
import { FormProps } from "./form";
import { StringToDecimalModifier } from "@simplr/react-forms/modifiers";

export type NumberOnChangeCallback = FieldOnChangeCallback<HTMLInputElement>;
Expand Down
8 changes: 2 additions & 6 deletions packages/react-forms-dom/src/components/password.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,8 @@ import { DomFieldProps } from "../contracts/field";

import { BaseDomField, BaseDomFieldState } from "../abstractions/base-dom-field";
import { FieldOnChangeCallback } from "../contracts/field";
import {
HTMLElementProps
} from "../contracts/field";
import {
FormProps
} from "../contracts/form";
import { HTMLElementProps } from "../contracts/field";
import { FormProps } from "./form";

export type PasswordOnChangeCallback = FieldOnChangeCallback<HTMLInputElement>;

Expand Down
2 changes: 1 addition & 1 deletion packages/react-forms-dom/src/components/radio-group.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as PropTypes from "prop-types";
import { BaseField, BaseFieldState } from "@simplr/react-forms";
import { FieldProps, FieldChildContext, FieldValue } from "@simplr/react-forms/contracts";
import { HTMLElementProps, DomFieldTemplateCallback } from "../contracts/field";
import { FormProps } from "../contracts/form";
import { FormProps } from "./form";
import { BaseDomField } from "../abstractions";
import { TypedRecord } from "typed-immutable-record";

Expand Down
8 changes: 2 additions & 6 deletions packages/react-forms-dom/src/components/search.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,8 @@ import { DomFieldProps } from "../contracts/field";

import { BaseDomField, BaseDomFieldState } from "../abstractions/base-dom-field";
import { FieldOnChangeCallback } from "../contracts/field";
import {
HTMLElementProps
} from "../contracts/field";
import {
FormProps
} from "../contracts/form";
import { HTMLElementProps } from "../contracts/field";
import { FormProps } from "./form";

export type SearchOnChangeCallback = FieldOnChangeCallback<HTMLInputElement>;

Expand Down
8 changes: 2 additions & 6 deletions packages/react-forms-dom/src/components/select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,8 @@ import { DomFieldProps } from "../contracts/field";

import { BaseDomField, BaseDomFieldState } from "../abstractions/base-dom-field";
import { FieldOnChangeCallback } from "../contracts/field";
import {
HTMLElementProps
} from "../contracts/field";
import {
FormProps
} from "../contracts/form";
import { HTMLElementProps } from "../contracts/field";
import { FormProps } from "./form";

export type SelectValue = string | string[];
export type SelectOnChangeCallback = FieldOnChangeCallback<HTMLSelectElement>;
Expand Down
4 changes: 1 addition & 3 deletions packages/react-forms-dom/src/components/text.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ import {
FieldOnChangeCallback,
HTMLElementProps
} from "../contracts/field";
import {
FormProps
} from "../contracts/form";
import { FormProps } from "./form";

export type TextOnChangeCallback = FieldOnChangeCallback<HTMLInputElement>;

Expand Down
4 changes: 1 addition & 3 deletions packages/react-forms-dom/src/components/textarea.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ import {
FieldOnChangeCallback,
HTMLElementProps
} from "../contracts/field";
import {
FormProps
} from "../contracts/form";
import { FormProps } from "./form";

export type TextAreaOnChangeCallback = FieldOnChangeCallback<HTMLTextAreaElement>;

Expand Down
10 changes: 2 additions & 8 deletions packages/react-forms-dom/src/contracts/form.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@ import * as React from "react";
import { FormError } from "@simplr/react-forms/contracts";
import { FormProps as CoreFormProps } from "@simplr/react-forms/contracts";
import { FormStore } from "@simplr/react-forms/stores";
import {
FieldOnChangeCallback,
FieldOnChangeInternalCallback,
DomFieldTemplateCallback
} from "../contracts/field";
import { DomFieldTemplateCallback } from "../contracts/field";

export interface FormOnSubmitInternalCallback {
(event: React.FormEvent<HTMLFormElement>, ...parameters: any[]): void | Promise<void> | FormError | string;
Expand All @@ -16,9 +12,7 @@ export interface FormOnSubmitCallback {
(event: React.FormEvent<HTMLFormElement>, store: FormStore): void | Promise<void> | FormError | string;
}

export interface FormProps extends CoreFormProps, React.HTMLProps<HTMLFormElement> {
onSubmit?: FormOnSubmitCallback & FormOnSubmitInternalCallback;
onChange?: FieldOnChangeCallback<any> & FieldOnChangeInternalCallback;
export interface BaseFormProps extends CoreFormProps {
preventSubmitDefaultAndPropagation?: boolean;
template?: DomFieldTemplateCallback;
// tslint:disable-next-line:max-line-length
Expand Down