x-ui-design 0.3.78 → 0.3.80
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 +21 -19
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +21 -19
- package/dist/index.js.map +1 -1
- package/lib/components/Form/Form.tsx +3 -3
- package/lib/hooks/useForm.ts +25 -19
- package/package.json +1 -1
package/dist/index.esm.js
CHANGED
|
@@ -607,7 +607,6 @@ const useForm = (initialValues = {}, onFieldsChange, onValuesChange, scrollToFir
|
|
|
607
607
|
...initialValues
|
|
608
608
|
});
|
|
609
609
|
const fieldInstancesRef = useRef({});
|
|
610
|
-
const [isSubmit, setIsSubmit] = useState(false);
|
|
611
610
|
const [isReseting, setIsReseting] = useState(false);
|
|
612
611
|
const [errors, setErrors] = useState({});
|
|
613
612
|
const fieldSubscribers = useRef({});
|
|
@@ -739,23 +738,28 @@ const useForm = (initialValues = {}, onFieldsChange, onValuesChange, scrollToFir
|
|
|
739
738
|
[name]: fieldErrors
|
|
740
739
|
}));
|
|
741
740
|
warningsRef.current[name] = fieldWarnings;
|
|
742
|
-
console.log({
|
|
743
|
-
isSubmit,
|
|
744
|
-
_scrollToFirstError: _scrollToFirstError.current
|
|
745
|
-
});
|
|
746
|
-
if (isSubmit || _scrollToFirstError.current) {
|
|
747
|
-
const firstErrorContent = document.querySelectorAll('.xUi-form-item-error')?.[0];
|
|
748
|
-
if (firstErrorContent) {
|
|
749
|
-
firstErrorContent.closest('.xUi-form-item')?.closest('[data-item="first-content"]')?.scrollIntoView();
|
|
750
|
-
setIsSubmit(false);
|
|
751
|
-
setScrollToFirstError(false);
|
|
752
|
-
}
|
|
753
|
-
}
|
|
754
741
|
return fieldErrors.length === 0;
|
|
755
742
|
}
|
|
756
743
|
async function validateFields(nameList) {
|
|
757
744
|
const fieldsToValidate = nameList || Object.keys(formRef.current);
|
|
758
745
|
const results = await Promise.all(fieldsToValidate.map(name => validateField(name)));
|
|
746
|
+
console.log(_scrollToFirstError.current);
|
|
747
|
+
if (_scrollToFirstError.current) {
|
|
748
|
+
const firstErrorContent = document.querySelectorAll('.xUi-form-item-error')?.[0];
|
|
749
|
+
console.log(firstErrorContent);
|
|
750
|
+
if (firstErrorContent) {
|
|
751
|
+
function findFormItem(item) {
|
|
752
|
+
console.log(item?.parentElement?.tagName);
|
|
753
|
+
if (item?.parentElement?.tagName !== 'FORM') {
|
|
754
|
+
findFormItem(item?.parentElement);
|
|
755
|
+
} else {
|
|
756
|
+
item.scrollIntoView();
|
|
757
|
+
}
|
|
758
|
+
}
|
|
759
|
+
findFormItem(firstErrorContent.closest('.xUi-form-item'));
|
|
760
|
+
setScrollToFirstError(false);
|
|
761
|
+
}
|
|
762
|
+
}
|
|
759
763
|
return results.every(valid => valid);
|
|
760
764
|
}
|
|
761
765
|
function resetFields(nameList, showError = true) {
|
|
@@ -781,7 +785,7 @@ const useForm = (initialValues = {}, onFieldsChange, onValuesChange, scrollToFir
|
|
|
781
785
|
setIsReseting(prev => !prev);
|
|
782
786
|
}
|
|
783
787
|
async function submit() {
|
|
784
|
-
|
|
788
|
+
setScrollToFirstError(true);
|
|
785
789
|
return (await validateFields()) ? formRef.current : undefined;
|
|
786
790
|
}
|
|
787
791
|
function subscribeToField(name, callback) {
|
|
@@ -1139,16 +1143,14 @@ const Form$1 = ({
|
|
|
1139
1143
|
formInstance.onValuesChange = onValuesChange;
|
|
1140
1144
|
}
|
|
1141
1145
|
}, [formInstance, onFieldsChange, onValuesChange]);
|
|
1142
|
-
const injectPropsIntoFinalLeaf =
|
|
1146
|
+
const injectPropsIntoFinalLeaf = child => {
|
|
1143
1147
|
if (! /*#__PURE__*/isValidElement(child)) {
|
|
1144
1148
|
return child;
|
|
1145
1149
|
}
|
|
1146
1150
|
const childProps = child.props;
|
|
1147
1151
|
const isWrapper = typeof child.type === 'string' && !('dangerouslySetInnerHTML' in childProps) && ['div', 'span', 'label'].includes(child.type);
|
|
1148
1152
|
if (isWrapper) {
|
|
1149
|
-
return /*#__PURE__*/React$1.createElement(child.type,
|
|
1150
|
-
"data-item": key == 0 ? 'first-content' : ''
|
|
1151
|
-
}), Children.map(flattenChildren(childProps.children), injectPropsIntoFinalLeaf));
|
|
1153
|
+
return /*#__PURE__*/React$1.createElement(child.type, childProps, Children.map(flattenChildren(childProps.children), injectPropsIntoFinalLeaf));
|
|
1152
1154
|
}
|
|
1153
1155
|
if (childProps?.__injected) {
|
|
1154
1156
|
return child;
|
|
@@ -1166,7 +1168,7 @@ const Form$1 = ({
|
|
|
1166
1168
|
ref: formRef,
|
|
1167
1169
|
onSubmit: handleSubmit,
|
|
1168
1170
|
className: `${prefixCls} ${className}`
|
|
1169
|
-
}, Children.map(childrenList,
|
|
1171
|
+
}, Children.map(childrenList, child => injectPropsIntoFinalLeaf(child))));
|
|
1170
1172
|
};
|
|
1171
1173
|
Form$1.Item = FormItem$1;
|
|
1172
1174
|
|