@dartech/arsenal-ui 1.4.11 → 1.4.12

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. package/index.js +28 -21
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -2306,23 +2306,29 @@ const ControlArrayInput = ({
2306
2306
  required,
2307
2307
  defaultValue: _defaultValue = null
2308
2308
  }) => {
2309
- var _a, _b, _c;
2309
+ var _a, _b;
2310
2310
  const [localValue, setLoacalValue] = useState('');
2311
2311
  const [error, setError] = useState(null);
2312
- const {
2313
- field: {
2312
+ const _c = useController({
2313
+ control,
2314
+ name,
2315
+ defaultValue: _defaultValue,
2316
+ rules: {
2317
+ required: required && DEFAULT_REQUIRED_ERROR_TEXT
2318
+ }
2319
+ }),
2320
+ _d = _c.field,
2321
+ {
2314
2322
  onChange,
2315
2323
  value: values
2316
- },
2317
- // fieldState: { error },
2318
- formState: {
2319
- errors
2320
- }
2321
- } = useController({
2322
- control,
2323
- name,
2324
- defaultValue: _defaultValue
2325
- });
2324
+ } = _d,
2325
+ fieldData = __rest(_d, ["onChange", "value"]),
2326
+ {
2327
+ // fieldState: { error },
2328
+ formState: {
2329
+ errors
2330
+ }
2331
+ } = _c;
2326
2332
  const handleInputChange = useCallback(e => {
2327
2333
  const {
2328
2334
  value
@@ -2330,15 +2336,16 @@ const ControlArrayInput = ({
2330
2336
  setLoacalValue(value);
2331
2337
  }, []);
2332
2338
  const handleAdd = useCallback(() => {
2333
- var _a;
2334
2339
  setError(null);
2335
- if (localValue && !((_a = errors[name]) === null || _a === void 0 ? void 0 : _a.message) && !(Array.isArray(values) && values.includes(localValue))) {
2340
+ if (localValue &&
2341
+ // !errors[name]?.message &&
2342
+ !(Array.isArray(values) && values.includes(localValue))) {
2336
2343
  onChange([...(values !== null && values !== void 0 ? values : []), localValue]);
2337
2344
  setLoacalValue('');
2338
2345
  } else if (Array.isArray(values) && values.includes(localValue)) {
2339
2346
  setError('This value already exists');
2340
2347
  }
2341
- }, [localValue, errors, name, onChange, values]);
2348
+ }, [localValue, onChange, values]);
2342
2349
  const handleDelete = useCallback(value => {
2343
2350
  onChange(values.filter(code => code !== value));
2344
2351
  }, [values, onChange]);
@@ -2376,9 +2383,10 @@ const ControlArrayInput = ({
2376
2383
  }, index))
2377
2384
  })), jsx("input", Object.assign({
2378
2385
  type: "hidden"
2379
- }, control.register(name, {
2380
- required: required && 'Please, add a value'
2381
- }))), jsx(TextField, {
2386
+ }, control.register(name), {
2387
+ onChange: onChange,
2388
+ value: values
2389
+ }, fieldData)), jsx(TextField, {
2382
2390
  fullWidth: true,
2383
2391
  variant: "outlined",
2384
2392
  size: "small",
@@ -2392,8 +2400,7 @@ const ControlArrayInput = ({
2392
2400
  InputProps: {
2393
2401
  endAdornment: jsx(IconButton, Object.assign({
2394
2402
  size: "small",
2395
- onClick: handleAdd,
2396
- disabled: !!((_c = errors[name]) === null || _c === void 0 ? void 0 : _c.message)
2403
+ onClick: handleAdd
2397
2404
  }, {
2398
2405
  children: jsx(SvgIcon, {
2399
2406
  children: jsx("path", {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dartech/arsenal-ui",
3
- "version": "1.4.11",
3
+ "version": "1.4.12",
4
4
  "author": "DAR",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/"