x-ui-design 0.6.59 → 0.6.61

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/index.esm.js CHANGED
@@ -624,18 +624,19 @@ const useForm = (initialValues = {}, onFieldsChange, onValuesChange, scrollToFir
624
624
  const errorSubscribers = useRef({});
625
625
  const fieldSubscribers = useRef({});
626
626
  const formSubscribers = useRef([]);
627
- function getFormFields() {
628
- return Object.assign({}, ...Object.values(formRef.current));
629
- }
627
+ // function getFormFields() {
628
+ // return formRef.current[stepRef.current]
629
+ // // return Object.assign({}, ...Object.values());
630
+ // }
630
631
  function getFieldInstance(name) {
631
632
  return name ? fieldInstancesRef.current[name] : fieldInstancesRef.current;
632
633
  }
633
634
  function getFieldValue(name) {
634
- const formData = getFormFields();
635
+ const formData = formRef.current[stepRef.current];
635
636
  return formData[name];
636
637
  }
637
638
  function getFieldsValue(nameList) {
638
- const formData = getFormFields();
639
+ const formData = formRef.current[stepRef.current];
639
640
  console.info({
640
641
  stepRef: stepRef.current,
641
642
  formRef: formRef.current
@@ -664,7 +665,13 @@ const useForm = (initialValues = {}, onFieldsChange, onValuesChange, scrollToFir
664
665
  if (!reset && reset !== null && ([undefined, null].includes(value) || formRef.current[stepRef.current][name] === value)) {
665
666
  return;
666
667
  }
667
- formRef.current[stepRef.current][name] = value;
668
+ if (reset === true) {
669
+ Object.entries(formRef.current).forEach(([key]) => {
670
+ formRef.current[+key][name] = value;
671
+ });
672
+ } else {
673
+ formRef.current[stepRef.current][name] = value;
674
+ }
668
675
  if (touch) {
669
676
  touchedFieldsRef.current.add(name);
670
677
  }
@@ -794,10 +801,11 @@ const useForm = (initialValues = {}, onFieldsChange, onValuesChange, scrollToFir
794
801
  return results.every(valid => valid);
795
802
  }
796
803
  function resetFields(nameList, showError = true) {
797
- const formData = getFormFields();
804
+ const formData = Object.assign({}, ...Object.values(formRef.current));
798
805
  if (nameList?.length) {
799
806
  nameList.forEach(name => {
800
807
  formData[name] = initialValues[name];
808
+ trashFormRef.current[name] = initialValues[name];
801
809
  touchedFieldsRef.current.delete(name);
802
810
  delete warningsRef.current[name];
803
811
  errorsRef.current[name] = [];
@@ -817,9 +825,9 @@ const useForm = (initialValues = {}, onFieldsChange, onValuesChange, scrollToFir
817
825
  setIsReseting(prev => !prev);
818
826
  }
819
827
  async function submit() {
820
- const formData = getFormFields();
828
+ const formData = Object.assign({}, ...Object.values(formRef.current));
821
829
  return (await validateFields()) ? (() => {
822
- formHandlersRef.current.onFinish?.(formData);
830
+ formHandlersRef.current.onFinish?.(Object.assign({}, ...Object.values(formRef.current)));
823
831
  return formData;
824
832
  })() : undefined;
825
833
  }
@@ -877,7 +885,6 @@ const useForm = (initialValues = {}, onFieldsChange, onValuesChange, scrollToFir
877
885
  }
878
886
  function changeStep(step) {
879
887
  stepRef.current = step ?? 0;
880
- console.info('stepRef', stepRef.current);
881
888
  if (!formRef.current[stepRef.current]) {
882
889
  formRef.current[stepRef.current] = {};
883
890
  }