react-better-html 1.1.63 → 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.
@@ -76,6 +76,8 @@ export declare function useForm<FormFields extends Record<string | number, strin
76
76
  reset: () => void;
77
77
  requiredFields: (keyof FormFields)[] | undefined;
78
78
  isDirty: boolean;
79
+ isValid: boolean;
80
+ canSubmit: boolean;
79
81
  };
80
82
  export declare function useUrlQuery(): {
81
83
  setQuery: (query: Record<string, string | number>, keepHistory?: boolean) => void;
@@ -379,6 +379,14 @@ function useForm(options) {
379
379
  setErrors({});
380
380
  }, [defaultValues]);
381
381
  const isDirty = (0, react_1.useMemo)(() => Object.keys(defaultValues).some((key) => defaultValues[key] !== values[key]), [defaultValues, values]);
382
+ const isValid = (0, react_1.useMemo)(() => {
383
+ const validationErrors = validate?.(values) || {};
384
+ return Object.keys(validationErrors).length === 0;
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]);
382
390
  return {
383
391
  values,
384
392
  errors,
@@ -396,6 +404,8 @@ function useForm(options) {
396
404
  reset,
397
405
  requiredFields,
398
406
  isDirty,
407
+ isValid,
408
+ canSubmit,
399
409
  };
400
410
  }
401
411
  function useUrlQuery() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-better-html",
3
- "version": "1.1.63",
3
+ "version": "1.1.65",
4
4
  "description": "A component library for react that is as close to plane html as possible",
5
5
  "main": "dist/index.js",
6
6
  "files": [