x-ui-design 0.3.49 → 0.3.52
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 +16 -16
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +16 -16
- package/dist/index.js.map +1 -1
- package/lib/components/Form/Item/Item.tsx +16 -16
- package/lib/hooks/useForm.ts +1 -0
- package/package.json +1 -1
- package/src/app/page.tsx +15 -1
package/dist/index.esm.js
CHANGED
|
@@ -709,6 +709,7 @@ const useForm = (initialValues = {}, onFieldsChange, onValuesChange) => {
|
|
|
709
709
|
const fieldWarnings = [];
|
|
710
710
|
await Promise.all([rules].flat(1).map(async rule => {
|
|
711
711
|
rule = typeof rule === 'function' ? rule(formInstance) : rule;
|
|
712
|
+
debugger;
|
|
712
713
|
if (rule.required && (rule.validateBooleanFalse && !value || value === undefined || value === null || value === '' || Array.isArray(value) && !value.length)) {
|
|
713
714
|
fieldErrors.push(rule.message || 'This field is required');
|
|
714
715
|
}
|
|
@@ -917,6 +918,7 @@ const FormItem$1 = ({
|
|
|
917
918
|
feedbackIcons,
|
|
918
919
|
...props
|
|
919
920
|
}) => {
|
|
921
|
+
const [_name] = useState(valuePropName || name);
|
|
920
922
|
const formContext = useContext(FormContext);
|
|
921
923
|
const errorRef = useRef(null);
|
|
922
924
|
if (!formContext) {
|
|
@@ -934,25 +936,25 @@ const FormItem$1 = ({
|
|
|
934
936
|
} = formContext;
|
|
935
937
|
const childrenList = useMemo(() => flattenChildren(children), [children]);
|
|
936
938
|
useEffect(() => {
|
|
937
|
-
if (
|
|
938
|
-
registerField(
|
|
939
|
+
if (_name && !getFieldInstance(_name)) {
|
|
940
|
+
registerField(_name, rules);
|
|
939
941
|
}
|
|
940
|
-
}, [
|
|
942
|
+
}, [_name, rules]);
|
|
941
943
|
useEffect(() => {
|
|
942
944
|
if (initialValue) {
|
|
943
|
-
setFieldValue(
|
|
945
|
+
setFieldValue(_name, initialValue);
|
|
944
946
|
}
|
|
945
947
|
}, []);
|
|
946
948
|
useEffect(() => {
|
|
947
|
-
if (
|
|
949
|
+
if (_name && dependencies.length > 0) {
|
|
948
950
|
const unsubscribe = subscribeToFields(dependencies, () => {
|
|
949
|
-
validateFields([
|
|
951
|
+
validateFields([_name]);
|
|
950
952
|
});
|
|
951
953
|
return () => {
|
|
952
954
|
unsubscribe();
|
|
953
955
|
};
|
|
954
956
|
}
|
|
955
|
-
}, [dependencies,
|
|
957
|
+
}, [dependencies, _name]);
|
|
956
958
|
useEffect(() => {
|
|
957
959
|
if (errorRef.current && errorRef.current?.clientHeight >= REF_CLIENT_HEIGHT) {
|
|
958
960
|
errorRef.current.style.position = 'relative';
|
|
@@ -960,7 +962,7 @@ const FormItem$1 = ({
|
|
|
960
962
|
}
|
|
961
963
|
}, [errorRef.current]);
|
|
962
964
|
const isRequired = useMemo(() => rules.some(rule => rule.required), [rules]);
|
|
963
|
-
const errorMessage = getFieldError(
|
|
965
|
+
const errorMessage = getFieldError(_name)?.[0];
|
|
964
966
|
return /*#__PURE__*/React$1.createElement("div", {
|
|
965
967
|
style: style,
|
|
966
968
|
className: clsx([`${prefixCls}`, {
|
|
@@ -968,10 +970,10 @@ const FormItem$1 = ({
|
|
|
968
970
|
[className]: className,
|
|
969
971
|
noStyle: props.noStyle
|
|
970
972
|
}])
|
|
971
|
-
}, !props.noStyle && (label ||
|
|
973
|
+
}, !props.noStyle && (label || _name) && /*#__PURE__*/React$1.createElement("label", {
|
|
972
974
|
className: `${prefixCls}-label`,
|
|
973
|
-
htmlFor:
|
|
974
|
-
}, label ||
|
|
975
|
+
htmlFor: _name
|
|
976
|
+
}, label || _name, ":", isRequired && /*#__PURE__*/React$1.createElement("span", {
|
|
975
977
|
className: `${prefixCls}-required`
|
|
976
978
|
}, "*")), Children.map(childrenList, (child, key) => {
|
|
977
979
|
if (/*#__PURE__*/isValidElement(child) && child.type !== Fragment) {
|
|
@@ -982,9 +984,9 @@ const FormItem$1 = ({
|
|
|
982
984
|
value,
|
|
983
985
|
...childProps
|
|
984
986
|
} = child.props;
|
|
985
|
-
const fieldValue = getFieldValue(
|
|
987
|
+
const fieldValue = getFieldValue(_name) ?? initialValue;
|
|
986
988
|
return /*#__PURE__*/React$1.createElement(FormItemChildComponent, _extends({}, childProps, {
|
|
987
|
-
name:
|
|
989
|
+
name: _name,
|
|
988
990
|
child: child,
|
|
989
991
|
value: value,
|
|
990
992
|
fieldValue: fieldValue,
|
|
@@ -993,7 +995,6 @@ const FormItem$1 = ({
|
|
|
993
995
|
key: `${key}_${isReseting}`,
|
|
994
996
|
error: Boolean(errorMessage),
|
|
995
997
|
setFieldValue: setFieldValue,
|
|
996
|
-
valuePropName: valuePropName,
|
|
997
998
|
feedbackIcons: feedbackIcons
|
|
998
999
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
999
1000
|
// @ts-expect-error
|
|
@@ -1015,7 +1016,6 @@ const FormItemChildComponent = ({
|
|
|
1015
1016
|
fieldValue,
|
|
1016
1017
|
setFieldValue,
|
|
1017
1018
|
onChange,
|
|
1018
|
-
valuePropName,
|
|
1019
1019
|
normalize,
|
|
1020
1020
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
1021
1021
|
noStyle,
|
|
@@ -1044,7 +1044,7 @@ const FormItemChildComponent = ({
|
|
|
1044
1044
|
return;
|
|
1045
1045
|
}
|
|
1046
1046
|
}
|
|
1047
|
-
setFieldValue(
|
|
1047
|
+
setFieldValue(name, rawValue);
|
|
1048
1048
|
onChange?.(e, option);
|
|
1049
1049
|
};
|
|
1050
1050
|
return /*#__PURE__*/React$1.createElement(child.type, _extends({}, props, {
|