From d1f880ec62b01f11ac6a21c68bcac0bff6804f59 Mon Sep 17 00:00:00 2001 From: Nerissa Aguirre Date: Wed, 27 Aug 2025 09:26:44 -0300 Subject: [PATCH 1/3] =?UTF-8?q?feat:=20exporta=20fun=C3=A7=C3=A3o=20de=20r?= =?UTF-8?q?eset=20form?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- demo/FormExamples.jsx | 39 +++++++++++++++++++++++++++++ src/forms/Form.jsx | 2 +- src/forms/FormActions.jsx | 5 ++-- src/forms/helpers/useFormControl.js | 1 + 4 files changed, 44 insertions(+), 3 deletions(-) diff --git a/demo/FormExamples.jsx b/demo/FormExamples.jsx index 951bea8..2c70c1e 100644 --- a/demo/FormExamples.jsx +++ b/demo/FormExamples.jsx @@ -20,6 +20,7 @@ import { export function FormExamples() { const [bootstrapFormValidation, setBootstrapFormValidation] = useState(false); const [changeCustomValidation, setChangeCustomValidation] = useState(false); + const [useCustomActions, setUseCustomActions] = useState(false); const validations = useMemo( () => ({ @@ -138,6 +139,20 @@ export function FormExamples() { }} customValidation={bootstrapFormValidation} validations={validations} + customActions={ + useCustomActions + ? (isSubmiting, { onCancel, resetForm }) => ( +
+ + +
+ ) + : undefined + } >
Form configuration:
setChangeCustomValidation(value)} /> + setUseCustomActions(value)} + />
@@ -734,10 +755,28 @@ export function FormExamples() { includeEmptyItem={false} menuClassName="p-4 w-100" /> + + ); } +const ResetForm = () => { + const formControl = useFormControl(); + + const reset = () => { + console.log('reset form'); + + formControl.resetFormData(); + }; + + return ( + + ); +}; + const FormSwitchExample = () => { const autocompleteField1FormControl = useFormControl('autocompleteField1'); diff --git a/src/forms/Form.jsx b/src/forms/Form.jsx index 8c61184..ea8ab05 100644 --- a/src/forms/Form.jsx +++ b/src/forms/Form.jsx @@ -76,7 +76,7 @@ export function Form({
{children} - + ); } diff --git a/src/forms/FormActions.jsx b/src/forms/FormActions.jsx index fde1c87..658caa3 100644 --- a/src/forms/FormActions.jsx +++ b/src/forms/FormActions.jsx @@ -2,9 +2,9 @@ import React from 'react'; import PropTypes from 'prop-types'; import { isFunction } from 'js-var-type'; -export function FormActions({ submitLabel, cancelLabel, onCancel, isSubmiting, customActions }) { +export function FormActions({ submitLabel, cancelLabel, onCancel, isSubmiting, customActions, resetForm }) { if (customActions) { - return isFunction(customActions) ? customActions(isSubmiting) : customActions; + return isFunction(customActions) ? customActions(isSubmiting, { onCancel, resetForm }) : customActions; } return ( @@ -25,4 +25,5 @@ FormActions.propTypes = { onCancel: PropTypes.func.isRequired, isSubmiting: PropTypes.bool, customActions: PropTypes.oneOfType([PropTypes.func, PropTypes.node]), + resetForm: PropTypes.func, }; diff --git a/src/forms/helpers/useFormControl.js b/src/forms/helpers/useFormControl.js index 2121ed8..bff92e9 100644 --- a/src/forms/helpers/useFormControl.js +++ b/src/forms/helpers/useFormControl.js @@ -48,6 +48,7 @@ export function useFormControl(name, type) { handleOnChange, register, getFormData: () => formState.getFormData(), + resetFormData: () => formState.reset(), isValid: () => formState.getValidationMessage(name) === '', getFormSubmitedAttempted: () => formState.getSubmitedAttempted(), }; From e7e5dd90581b6f59bfa67767569ae99e0e6964bc Mon Sep 17 00:00:00 2001 From: Nerissa Aguirre Date: Wed, 27 Aug 2025 09:51:45 -0300 Subject: [PATCH 2/3] fix PropTypes --- demo/FormExamples.jsx | 1 + src/forms/Form.jsx | 2 +- src/forms/FormActions.jsx | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/demo/FormExamples.jsx b/demo/FormExamples.jsx index 2c70c1e..6d78495 100644 --- a/demo/FormExamples.jsx +++ b/demo/FormExamples.jsx @@ -21,6 +21,7 @@ export function FormExamples() { const [bootstrapFormValidation, setBootstrapFormValidation] = useState(false); const [changeCustomValidation, setChangeCustomValidation] = useState(false); const [useCustomActions, setUseCustomActions] = useState(false); + console.log('🚀 ~ FormExamples ~ useCustomActions:', useCustomActions); const validations = useMemo( () => ({ diff --git a/src/forms/Form.jsx b/src/forms/Form.jsx index ea8ab05..23ded04 100644 --- a/src/forms/Form.jsx +++ b/src/forms/Form.jsx @@ -92,7 +92,7 @@ Form.defaultProps = { Form.propTypes = { cancelLabel: PropTypes.string, children: PropTypes.oneOfType([PropTypes.node, PropTypes.arrayOf(PropTypes.node)]), - customActions: PropTypes.oneOfType([PropTypes.node, PropTypes.arrayOf(PropTypes.node)]), + customActions: PropTypes.oneOfType([PropTypes.func, PropTypes.node, PropTypes.arrayOf(PropTypes.node)]), customValidation: PropTypes.bool, initialValues: PropTypes.object, onCancel: PropTypes.func, diff --git a/src/forms/FormActions.jsx b/src/forms/FormActions.jsx index 658caa3..9bb07c1 100644 --- a/src/forms/FormActions.jsx +++ b/src/forms/FormActions.jsx @@ -24,6 +24,6 @@ FormActions.propTypes = { cancelLabel: PropTypes.oneOfType([PropTypes.func, PropTypes.node]), onCancel: PropTypes.func.isRequired, isSubmiting: PropTypes.bool, - customActions: PropTypes.oneOfType([PropTypes.func, PropTypes.node]), + customActions: PropTypes.oneOfType([PropTypes.func, PropTypes.node, PropTypes.arrayOf(PropTypes.node)]), resetForm: PropTypes.func, }; From 13101ce099f34df6344c3656acd87455ee63c4ac Mon Sep 17 00:00:00 2001 From: Nerissa Aguirre Date: Thu, 28 Aug 2025 15:40:38 -0300 Subject: [PATCH 3/3] =?UTF-8?q?coment=C3=A1rio=20da=20revis=C3=A3o.=20Obri?= =?UTF-8?q?gada=20Caio!?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- demo/FormExamples.jsx | 1 - 1 file changed, 1 deletion(-) diff --git a/demo/FormExamples.jsx b/demo/FormExamples.jsx index 6d78495..2c70c1e 100644 --- a/demo/FormExamples.jsx +++ b/demo/FormExamples.jsx @@ -21,7 +21,6 @@ export function FormExamples() { const [bootstrapFormValidation, setBootstrapFormValidation] = useState(false); const [changeCustomValidation, setChangeCustomValidation] = useState(false); const [useCustomActions, setUseCustomActions] = useState(false); - console.log('🚀 ~ FormExamples ~ useCustomActions:', useCustomActions); const validations = useMemo( () => ({