Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix #86: remove param useNextResponse #87

Merged
merged 2 commits into from
Aug 11, 2024
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
1 change: 0 additions & 1 deletion src/MetaformRenderer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,6 @@ export default class MetaFormRenderer extends React.Component<IFormRenderer> {
formValidated={(validated) => {
this.setState({ validated });
}}
useNextResponse={this.props.useNextResponse}
/>
</Container>
</FormImplsContext.Provider>
Expand Down
1 change: 0 additions & 1 deletion src/constants/common-interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@
openTo?: Array<string>;

// autocomplete
autocomplete?: any;

Check warning on line 89 in src/constants/common-interface.ts

View workflow job for this annotation

GitHub Actions / build (16.x)

Unexpected any. Specify a different type

// file input
accept?: string;
Expand Down Expand Up @@ -202,7 +202,6 @@
/** */
changeResponseMode?: TChangeMode;
pageNumber?: number;
useNextResponse?: boolean;

/**
* REST API configruation params in the form
Expand All @@ -214,7 +213,7 @@
*/
onChange?: (change: IFieldChange, formData?: IFormData) => void;
onCustom?: (formData: IFormData, e: SyntheticEvent) => TFormResponse;
onError?: (errorResponse: any) => TFormResponse;

Check warning on line 216 in src/constants/common-interface.ts

View workflow job for this annotation

GitHub Actions / build (16.x)

Unexpected any. Specify a different type
onPopupClose?: (params: Array<unknown>) => void;
onPrevious?: (formData: IFormData, pageNumber: number) => TFormResponse;
onNext?: (
Expand Down
11 changes: 7 additions & 4 deletions src/form/Form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ interface IProps {
}
) => void;
buttons?: IElementTypes;
useNextResponse?: boolean;
validate: (e: SyntheticEvent, type: string) => boolean;
formValidated: (validated: boolean) => void;
}
Expand Down Expand Up @@ -58,17 +57,21 @@ function Form(props: IProps) {
};

const handleNext = async (e: React.MouseEvent, section: IField, callback: TCallback) => {
if (!props.onNext) {
return;
}

if (props.validate(e, FORM_ACTION.NEXT)) {
if (props.useNextResponse === true) {
const result = await props.onNext();
const onNextResponse = props.onNext();
if (onNextResponse instanceof Promise) {
const result = await onNextResponse;
if (result) {
props.emit(EVENTS.SWITCH, {
payload: FORM_ACTION.NEXT,
callback
});
}
} else {
props.onNext();
props.emit(EVENTS.SWITCH, { payload: FORM_ACTION.NEXT, callback });
}
} else {
Expand Down
Loading