diff --git a/src/constants/constants.ts b/src/constants/constants.ts index e0f2bd7..c78eaa4 100644 --- a/src/constants/constants.ts +++ b/src/constants/constants.ts @@ -104,8 +104,8 @@ export const EVENTS = { PAGE_CHANGE: "page_change", _FIELD_CHANGE: "$field_change", _FIELD_CLOSE: "$field_close", - _DISABLE_TAB: "$disable-tab", - _ENABLE_CURRENT_TAB: "$enable-current-tab", + _DISABLE_TAB: "$disable_tab", + _ENABLE_CURRENT_TAB: "$enable_current_tab", _END_OF_PAGE: "$end_of_page", _RESET_END_OF_PAGE: "$reset_end_of_page" }; diff --git a/src/core/MetaForm.tsx b/src/core/MetaForm.tsx index b6e04b2..49f3a57 100644 --- a/src/core/MetaForm.tsx +++ b/src/core/MetaForm.tsx @@ -490,10 +490,10 @@ export default class MetaForm implements IMetaForm { const { eventType, payload } = changes; if (value !== undefined) { if (value === fieldValue) { - this.emit(eventType as string, payload); + this.emit(eventType as string, { payload }); } } else { - this.emit(eventType as string, payload); + this.emit(eventType as string, { payload }); } } break; diff --git a/src/form/Form.tsx b/src/form/Form.tsx index 5b2d43e..416952c 100644 --- a/src/form/Form.tsx +++ b/src/form/Form.tsx @@ -80,6 +80,7 @@ function Form(props: IProps) { props.emit(EVENTS.SWITCH, { payload: FORM_ACTION.PREVIOUS }); props.onPrevious(); }; + if (hasSection && sectionLayout !== SECTION_LAYOUT.DEFAULT) { return ( ; } @@ -27,7 +29,10 @@ function FormFieldRenderer(props: IRenderField) { } if (isSection) { return ( - + void; }) { - const vs = "my-2 my-md-3"; const type = props.meta?.type ? props.meta.type : "field"; const wrapClassName = cssClassName || (type === "field" ? "mcol-md-12" : ""); if (wrapClassName) { return ( {props.meta.displayProps?.rs &&
} -
+
{isSection && props.meta.displayType === "title" && (

{props.meta.displayName}

)} @@ -103,7 +107,7 @@ function RenderColumn({ form={props.form[field.name]} sync={sync} /> - ))} + ))}
); diff --git a/src/form/form-controls/Footer/Footer.tsx b/src/form/form-controls/Footer/Footer.tsx index d67d2a0..a2eb738 100644 --- a/src/form/form-controls/Footer/Footer.tsx +++ b/src/form/form-controls/Footer/Footer.tsx @@ -74,8 +74,13 @@ function Footer(props: IProps) { props.onCustom(e, button, callback); } }; + return ( - + {props.formButtons.map((button: IField, idx: number) => { const className = FormUtils.getCssClassName(button.meta?.displayProps); const subprops = { @@ -156,7 +161,7 @@ const FooterStyled = styled(Row)<{ useDefault: boolean }>` gap: 1.5rem; margin-top: 1.5rem; justify-content: flex-end; - ${(props) => + ${(props) => props.useDefault ? ` display: flex; diff --git a/src/form/form-group/BaseFormGroup.tsx b/src/form/form-group/BaseFormGroup.tsx index d21ecfb..4d81074 100644 --- a/src/form/form-group/BaseFormGroup.tsx +++ b/src/form/form-group/BaseFormGroup.tsx @@ -50,12 +50,24 @@ export default abstract class BaseFormGroup extends React.Component { }); this.context.listener(EVENTS.SWITCH, (payload: { payload: string; callback?: TCallback }) => { switch (payload.payload) { - case "next": - this.setActiveIndex(this.state.activeIndex + 1, payload.callback); - break; - case "previous": - this.setActiveIndex(this.state.activeIndex - 1, payload.callback); - break; + case "next": { + const nextIndex = this.getNextAvailableIndex(this.state.activeIndex + 1); + if (nextIndex >= 0) { + this.setActiveIndex(nextIndex, payload.callback); + } + const hasMorePages = this.getNextAvailableIndex(nextIndex + 1) === -1 ? false : true; + if (!hasMorePages) { + this.context.emit(EVENTS._END_OF_PAGE, { payload: nextIndex + 1}); + } + } + break; + case "previous": { + const previousIndex = this.getPreviousAvailableIndex(this.state.activeIndex - 1); + if (previousIndex >= 0) { + this.setActiveIndex(previousIndex, payload.callback); + } + } + break; } }); this.context.listener(EVENTS.VALIDATION_ERROR, (payload: { payload: string; callback: TCallback }) => { @@ -142,6 +154,28 @@ export default abstract class BaseFormGroup extends React.Component { }); } + getNextAvailableIndex(index: number): number { + if (this.tabFields.length > index) { + if (this.tabFields[index]?.meta?.isDisabled === true) { + return this.getNextAvailableIndex(index + 1); + } else { + return index; + } + } + return -1; + } + + getPreviousAvailableIndex(index: number): number { + if (this.tabFields.length > index) { + if (this.tabFields[index]?.meta?.isDisabled === true) { + return this.getPreviousAvailableIndex(index - 1); + } else { + return index; + } + } + return -1; + } + abstract tabs(): JSX.Element; abstract panels(): JSX.Element; } diff --git a/src/form/form-group/common/Section.tsx b/src/form/form-group/common/Section.tsx index 5e349a9..3e88df8 100644 --- a/src/form/form-group/common/Section.tsx +++ b/src/form/form-group/common/Section.tsx @@ -32,7 +32,10 @@ export function Section(props: ISectionProps) { role="tabpanel" aria-labelledby={props.section.name} > - + {props.section.fields && props.section.fields.map((field: IField) => ( + {fields.map((field) => (