@gravity-ui/dynamic-forms 1.6.1 → 1.6.2

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/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # Changelog
2
2
 
3
+ ## [1.6.2](https://github.com/gravity-ui/dynamic-forms/compare/v1.6.1...v1.6.2) (2023-05-16)
4
+
5
+
6
+ ### Bug Fixes
7
+
8
+ * add css rule for errors ([#41](https://github.com/gravity-ui/dynamic-forms/issues/41)) ([a6661bc](https://github.com/gravity-ui/dynamic-forms/commit/a6661bcd3a86a29ec3b457bccbf6d8f46aaf0408))
9
+ * add number value transform ([#40](https://github.com/gravity-ui/dynamic-forms/issues/40)) ([d422d90](https://github.com/gravity-ui/dynamic-forms/commit/d422d901e675c6f7014a07f9bfae972fcd555b76))
10
+
3
11
  ## [1.6.1](https://github.com/gravity-ui/dynamic-forms/compare/v1.6.0...v1.6.1) (2023-05-02)
4
12
 
5
13
 
@@ -52,7 +52,10 @@ const useField = ({ name, spec, initialValue, validate: propsValidate, tools, pa
52
52
  setState((state) => {
53
53
  const _value = lodash_1.default.isFunction(valOrSetter) ? valOrSetter(state.value) : valOrSetter;
54
54
  const error = validate === null || validate === void 0 ? void 0 : validate(_value);
55
- const value = (0, utils_1.transformArrIn)(_value);
55
+ let value = (0, utils_1.transformArrIn)(_value);
56
+ if ((0, helpers_1.isNumberSpec)(spec) && value && !error) {
57
+ value = Number(value);
58
+ }
56
59
  let newChildErrors = Object.assign({}, state.childErrors);
57
60
  if (childErrors) {
58
61
  const nearestChildName = lodash_1.default.keys(childErrors).sort((a, b) => a.length - b.length)[0];
@@ -73,7 +76,7 @@ const useField = ({ name, spec, initialValue, validate: propsValidate, tools, pa
73
76
  }
74
77
  };
75
78
  return { onChange, onDrop };
76
- }, [initialValue, setState, name, validate]);
79
+ }, [initialValue, setState, name, validate, spec]);
77
80
  const onBlur = react_1.default.useCallback(() => {
78
81
  setState((state) => (Object.assign(Object.assign({}, state), { active: false, touched: true })));
79
82
  }, [setState]);
@@ -12,6 +12,7 @@
12
12
  .df-error-wrapper_error .g-select:not(.df-error-wrapper-ignore) .g-select-control::before,
13
13
  .df-error-wrapper_error .g-select:hover:not(.df-error-wrapper-ignore) .g-select-control_open::before,
14
14
  .df-error-wrapper_error .yc-text-input_view_normal:not(.df-error-wrapper-ignore) .yc-text-input__control,
15
+ .df-error-wrapper_error .yc-text-input_view_normal:not(.df-error-wrapper-ignore) .yc-text-input__content,
15
16
  .df-error-wrapper_error .yc-checkbox__indicator:not(.df-error-wrapper-ignore)::before {
16
17
  border-color: var(--yc-color-text-danger);
17
18
  }
@@ -1,6 +1,6 @@
1
1
  import React from 'react';
2
2
  import _ from 'lodash';
3
- import { isArraySpec, isObjectSpec, isReact18OrMore } from '../../../helpers';
3
+ import { isArraySpec, isNumberSpec, isObjectSpec, isReact18OrMore } from '../../../helpers';
4
4
  import { OBJECT_ARRAY_CNT, OBJECT_ARRAY_FLAG, REMOVED_ITEM } from '../constants';
5
5
  import { isArrayItem, transformArrIn, transformArrOut } from '../utils';
6
6
  export const useField = ({ name, spec, initialValue, validate: propsValidate, tools, parentOnChange, parentOnUnmount, }) => {
@@ -48,7 +48,10 @@ export const useField = ({ name, spec, initialValue, validate: propsValidate, to
48
48
  setState((state) => {
49
49
  const _value = _.isFunction(valOrSetter) ? valOrSetter(state.value) : valOrSetter;
50
50
  const error = validate === null || validate === void 0 ? void 0 : validate(_value);
51
- const value = transformArrIn(_value);
51
+ let value = transformArrIn(_value);
52
+ if (isNumberSpec(spec) && value && !error) {
53
+ value = Number(value);
54
+ }
52
55
  let newChildErrors = Object.assign({}, state.childErrors);
53
56
  if (childErrors) {
54
57
  const nearestChildName = _.keys(childErrors).sort((a, b) => a.length - b.length)[0];
@@ -69,7 +72,7 @@ export const useField = ({ name, spec, initialValue, validate: propsValidate, to
69
72
  }
70
73
  };
71
74
  return { onChange, onDrop };
72
- }, [initialValue, setState, name, validate]);
75
+ }, [initialValue, setState, name, validate, spec]);
73
76
  const onBlur = React.useCallback(() => {
74
77
  setState((state) => (Object.assign(Object.assign({}, state), { active: false, touched: true })));
75
78
  }, [setState]);
@@ -12,6 +12,7 @@
12
12
  .df-error-wrapper_error .g-select:not(.df-error-wrapper-ignore) .g-select-control::before,
13
13
  .df-error-wrapper_error .g-select:hover:not(.df-error-wrapper-ignore) .g-select-control_open::before,
14
14
  .df-error-wrapper_error .yc-text-input_view_normal:not(.df-error-wrapper-ignore) .yc-text-input__control,
15
+ .df-error-wrapper_error .yc-text-input_view_normal:not(.df-error-wrapper-ignore) .yc-text-input__content,
15
16
  .df-error-wrapper_error .yc-checkbox__indicator:not(.df-error-wrapper-ignore)::before {
16
17
  border-color: var(--yc-color-text-danger);
17
18
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gravity-ui/dynamic-forms",
3
- "version": "1.6.1",
3
+ "version": "1.6.2",
4
4
  "description": "",
5
5
  "license": "MIT",
6
6
  "main": "build/cjs/index.js",