react-better-html 1.1.64 → 1.1.65
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/utils/hooks.d.ts +1 -0
- package/dist/utils/hooks.js +5 -0
- package/package.json +1 -1
package/dist/utils/hooks.d.ts
CHANGED
|
@@ -77,6 +77,7 @@ export declare function useForm<FormFields extends Record<string | number, strin
|
|
|
77
77
|
requiredFields: (keyof FormFields)[] | undefined;
|
|
78
78
|
isDirty: boolean;
|
|
79
79
|
isValid: boolean;
|
|
80
|
+
canSubmit: boolean;
|
|
80
81
|
};
|
|
81
82
|
export declare function useUrlQuery(): {
|
|
82
83
|
setQuery: (query: Record<string, string | number>, keepHistory?: boolean) => void;
|
package/dist/utils/hooks.js
CHANGED
|
@@ -383,6 +383,10 @@ function useForm(options) {
|
|
|
383
383
|
const validationErrors = validate?.(values) || {};
|
|
384
384
|
return Object.keys(validationErrors).length === 0;
|
|
385
385
|
}, [validate, values]);
|
|
386
|
+
const canSubmit = (0, react_1.useMemo)(() => {
|
|
387
|
+
const requiredFieldsHaveValues = requiredFields?.every((field) => values[field] !== undefined && values[field] !== "") ?? true;
|
|
388
|
+
return isValid && requiredFieldsHaveValues;
|
|
389
|
+
}, [isValid, requiredFields]);
|
|
386
390
|
return {
|
|
387
391
|
values,
|
|
388
392
|
errors,
|
|
@@ -401,6 +405,7 @@ function useForm(options) {
|
|
|
401
405
|
requiredFields,
|
|
402
406
|
isDirty,
|
|
403
407
|
isValid,
|
|
408
|
+
canSubmit,
|
|
404
409
|
};
|
|
405
410
|
}
|
|
406
411
|
function useUrlQuery() {
|