x-ui-design 0.6.30 → 0.6.32

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.
@@ -1,7 +1,7 @@
1
1
  import { RuleTypes } from '../types';
2
2
  import type { FieldData, FieldError, FormInstance } from '../types/form';
3
3
  declare const useForm: ({ initialValues, onFieldsChange, onValuesChange, scrollToFirstError, onFinish, onFinishFailed }: {
4
- initialValues: Record<string, RuleTypes>;
4
+ initialValues?: Record<string, RuleTypes>;
5
5
  onFieldsChange?: (changedFields: FieldData[]) => void;
6
6
  onValuesChange?: (changedValues: Record<string, RuleTypes>, allValues: Record<string, RuleTypes>) => void;
7
7
  scrollToFirstError?: boolean;
package/dist/index.esm.js CHANGED
@@ -780,6 +780,13 @@ const useForm = ({
780
780
  async function validateFields(nameList) {
781
781
  const fieldsToValidate = nameList || Object.keys(formRef.current[stepRef.current]);
782
782
  const results = await Promise.all(fieldsToValidate.map(name => validateField(name)));
783
+ const errorFields = formInstance.getFieldsError().filter(e => e.errors.length);
784
+ if (errorFields.length) {
785
+ formHandlersRef.current.onFinishFailed?.({
786
+ values: formInstance.getFieldsValue(),
787
+ errorFields
788
+ });
789
+ }
783
790
  if (_scrollToFirstError.current) {
784
791
  const firstErrorContent = document.querySelectorAll('.xUi-form-item-has-error')?.[0];
785
792
  if (firstErrorContent) {
@@ -823,14 +830,7 @@ const useForm = ({
823
830
  return (await validateFields()) ? (() => {
824
831
  formHandlersRef.current.onFinish?.(formData);
825
832
  return formData;
826
- })() : (() => {
827
- const errorFields = formInstance.getFieldsError();
828
- formHandlersRef.current.onFinishFailed?.({
829
- values: formInstance.getFieldsValue(),
830
- errorFields
831
- });
832
- return undefined;
833
- })();
833
+ })() : undefined;
834
834
  }
835
835
  function subscribeToField(name, callback) {
836
836
  if (!fieldSubscribers.current[name]) {
@@ -1229,7 +1229,7 @@ const Form$1 = ({
1229
1229
  if (await formInstance.validateFields()) {
1230
1230
  onFinish?.(formInstance.getFieldsValue());
1231
1231
  } else if (onFinishFailed) {
1232
- const errorFields = formInstance.getFieldsError();
1232
+ const errorFields = formInstance.getFieldsError().filter(e => e.errors.length);
1233
1233
  onFinishFailed({
1234
1234
  values: formInstance.getFieldsValue(),
1235
1235
  errorFields