@rolster/react-forms 18.11.4 → 18.12.0

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/cjs/index.js CHANGED
@@ -7,10 +7,11 @@ var helpers = require('@rolster/forms/helpers');
7
7
  var uuid = require('uuid');
8
8
  var react = require('react');
9
9
 
10
- class RolsterReactArrayControl {
10
+ class RolsterArrayControl {
11
11
  constructor(options) {
12
- this.initialValue = options.initialValue;
13
12
  this.uuid = options.uuid;
13
+ this.value = options.value;
14
+ this.initialValue = options.initialValue;
14
15
  this.focused = !!options.focused;
15
16
  this.unfocused = !this.focused;
16
17
  this.touched = !!options.touched;
@@ -19,36 +20,42 @@ class RolsterReactArrayControl {
19
20
  this.pristine = !this.dirty;
20
21
  this.disabled = !!options.disabled;
21
22
  this.enabled = !this.disabled;
22
- const { value, validators } = options;
23
- this.value = value;
24
- this.validators = validators;
25
- this.errors = validators ? helpers.controlIsValid({ value, validators }) : [];
23
+ this.valid = this.isValid(options.errors);
24
+ this.invalid = !this.valid;
25
+ this.wrong = this.touched && this.invalid;
26
+ this.errors = options.errors;
26
27
  this.error = this.errors[0];
28
+ this.validators = options.validators;
27
29
  }
28
30
  focus() {
29
- this.unfocused && this.refresh({ focused: true });
31
+ this.unfocused && this.refresh('focused', { focused: true });
30
32
  }
31
33
  blur() {
32
- this.focused && this.refresh({ focused: false, touched: true });
34
+ this.focused && this.refresh('focused', { focused: false, touched: true });
33
35
  }
34
36
  disable() {
35
- this.enabled && this.refresh({ disabled: true });
37
+ this.enabled && this.refresh('disabled', { disabled: true });
36
38
  }
37
39
  enable() {
38
- this.disabled && this.refresh({ disabled: false });
40
+ this.disabled && this.refresh('disabled', { disabled: false });
39
41
  }
40
42
  touch() {
41
- this.untouched && this.refresh({ touched: true });
43
+ this.untouched && this.refresh('touched', { touched: true });
42
44
  }
43
45
  setInitialValue(value) {
44
- this.initialValue = value;
45
- this.setValue(value);
46
+ const { validators } = this;
47
+ const errors = validators ? helpers.controlIsValid({ value, validators }) : [];
48
+ this.refresh('value', { dirty: false, errors, initialValue: value, value });
46
49
  }
47
50
  setValue(value) {
48
- this.refresh({ value });
51
+ const { validators } = this;
52
+ const errors = validators ? helpers.controlIsValid({ value, validators }) : [];
53
+ this.refresh('value', { dirty: true, errors, value });
49
54
  }
50
55
  setValidators(validators) {
51
- this.refresh({ validators });
56
+ const { value } = this;
57
+ const errors = validators ? helpers.controlIsValid({ value, validators }) : [];
58
+ this.refresh('validators', { errors, validators });
52
59
  }
53
60
  subscribe(subscriber) {
54
61
  this.subscriber = subscriber;
@@ -60,37 +67,37 @@ class RolsterReactArrayControl {
60
67
  return helpers.someErrors(this.errors, keys);
61
68
  }
62
69
  reset() {
63
- this.refresh({
70
+ const { initialValue: value, validators } = this;
71
+ const errors = validators ? helpers.controlIsValid({ value, validators }) : [];
72
+ this.refresh('reset', {
64
73
  dirty: false,
74
+ errors,
65
75
  touched: false,
66
- value: this.initialValue
76
+ value
67
77
  });
68
78
  }
69
- refresh(changes) {
70
- this.subscriber &&
71
- this.subscriber({
72
- ...this,
73
- ...changes,
74
- initialValue: this.initialValue
75
- });
79
+ isValid(errors) {
80
+ return errors.length === 0;
81
+ }
82
+ builder(options) {
83
+ return new RolsterArrayControl({ ...this, ...options });
84
+ }
85
+ refresh(action, options) {
86
+ this.subscriber && this.subscriber(action, this.builder(options));
76
87
  }
77
88
  }
78
- class RolsterArrayControl extends RolsterReactArrayControl {
89
+ class ReactRolsterArrayControl extends RolsterArrayControl {
79
90
  constructor(options) {
80
- super(options);
81
- this.valid = this.errors.length === 0;
82
- this.invalid = !this.valid;
83
- this.wrong = this.touched && this.invalid;
84
- }
85
- clone(options) {
86
- return new RolsterArrayControl(options);
91
+ const { value, validators } = options;
92
+ const errors = validators ? helpers.controlIsValid({ value, validators }) : [];
93
+ super({ ...options, errors });
87
94
  }
88
95
  }
89
96
  function rolsterArrayControl(options, validators) {
90
- const controlOptions = _arguments.createFormControlOptions(options, validators);
91
- return new RolsterArrayControl({
92
- ...controlOptions,
93
- initialValue: controlOptions.value,
97
+ const _options = _arguments.createFormControlOptions(options, validators);
98
+ return new ReactRolsterArrayControl({
99
+ ..._options,
100
+ initialValue: _options.value,
94
101
  uuid: uuid.v4()
95
102
  });
96
103
  }
@@ -104,49 +111,112 @@ function inputArrayControl(options, validators) {
104
111
  return rolsterArrayControl(options, validators);
105
112
  }
106
113
 
107
- class RolsterArrayGroup {
114
+ function replaceControl(controls, control) {
115
+ return Object.entries(controls).reduce((controls, [key, _control]) => {
116
+ if (_control.uuid === control.uuid) {
117
+ controls[key] = control;
118
+ }
119
+ return controls;
120
+ }, controls);
121
+ }
122
+
123
+ function refactorForValid$2(controls, validators) {
124
+ const errors = validators ? helpers.groupIsValid({ controls, validators }) : [];
125
+ return {
126
+ errors,
127
+ valid: errors.length === 0 && helpers.controlsAllChecked(controls, 'valid')
128
+ };
129
+ }
130
+ function refactorForControls$1(group, controls, action) {
131
+ switch (action) {
132
+ case 'focused':
133
+ case 'touched':
134
+ return {
135
+ touched: helpers.controlsPartialChecked(controls, 'touched'),
136
+ toucheds: helpers.controlsAllChecked(controls, 'touched')
137
+ };
138
+ case 'validators':
139
+ return refactorForValid$2(controls, group.validators);
140
+ case 'reset':
141
+ return {
142
+ ...refactorForValid$2(controls, group.validators),
143
+ dirty: helpers.controlsPartialChecked(controls, 'dirty'),
144
+ dirties: helpers.controlsAllChecked(controls, 'dirty'),
145
+ touched: helpers.controlsPartialChecked(controls, 'touched'),
146
+ toucheds: helpers.controlsAllChecked(controls, 'touched'),
147
+ value: helpers.controlsToValue(controls)
148
+ };
149
+ case 'list':
150
+ case 'value':
151
+ return {
152
+ ...refactorForValid$2(controls, group.validators),
153
+ dirty: helpers.controlsPartialChecked(controls, 'dirty'),
154
+ dirties: helpers.controlsAllChecked(controls, 'dirty'),
155
+ value: helpers.controlsToValue(controls)
156
+ };
157
+ default:
158
+ return {};
159
+ }
160
+ }
161
+ class BaseArrayGroup {
108
162
  constructor(options) {
109
- const { controls, resource, uuid, validators } = options;
110
- this.uuid = uuid;
111
- this.controls = controls;
112
- this.validators = validators;
113
- this.resource = resource;
114
- this.errors = validators ? helpers.groupIsValid({ controls, validators }) : [];
115
- this.error = this.errors[0];
116
- this.valid =
117
- this.errors.length === 0 && helpers.controlsAllChecked(controls, 'valid');
118
- this.invalid = !this.valid;
119
- this.dirty = helpers.controlsPartialChecked(controls, 'dirty');
120
- this.dirties = helpers.controlsAllChecked(controls, 'dirty');
121
- this.touched = helpers.controlsPartialChecked(controls, 'touched');
122
- this.toucheds = helpers.controlsAllChecked(controls, 'touched');
163
+ this.uuid = options.uuid;
164
+ this.controls = options.controls;
165
+ this.value = options.value;
166
+ this.resource = options.resource;
167
+ this.dirty = !!options.dirty;
168
+ this.dirties = !!options.dirties;
123
169
  this.pristine = !this.dirty;
124
170
  this.pristines = !this.dirties;
171
+ this.touched = !!options.touched;
172
+ this.toucheds = !!options.toucheds;
125
173
  this.untouched = !this.touched;
126
174
  this.untoucheds = !this.toucheds;
175
+ this.valid = !!options.valid;
176
+ this.invalid = !this.valid;
127
177
  this.wrong = this.touched && this.invalid;
128
- this.value = helpers.controlsToValue(controls);
129
- const subscriber = (options) => {
130
- this.refresh({
131
- controls: Object.entries(this.controls).reduce((controls, [key, control]) => {
132
- controls[key] =
133
- control.uuid === options.uuid ? control.clone(options) : control;
134
- return controls;
135
- }, {})
178
+ this.errors = options.errors;
179
+ this.error = this.errors[0];
180
+ this.validators = options.validators;
181
+ const subscriber = (action, control) => {
182
+ const controls = replaceControl(this.controls, control);
183
+ this.refresh(action, {
184
+ ...refactorForControls$1(this, controls, action),
185
+ controls
136
186
  });
137
187
  };
138
- Object.values(controls).forEach((control) => {
188
+ Object.values(this.controls).forEach((control) => {
139
189
  control.subscribe(subscriber);
140
190
  });
141
191
  }
142
- setValidators(validators) {
143
- this.refresh({ validators });
144
- }
145
192
  subscribe(subscriber) {
146
193
  this.subscriber = subscriber;
147
194
  }
148
- refresh(changes) {
149
- this.subscriber && this.subscriber({ ...this, ...changes });
195
+ setValidators(validators) {
196
+ this.refresh('validators', {
197
+ ...refactorForValid$2(this.controls, validators),
198
+ validators
199
+ });
200
+ }
201
+ refresh(action, options) {
202
+ this.subscriber &&
203
+ this.subscriber(action, new BaseArrayGroup({ ...this, ...options }));
204
+ }
205
+ }
206
+ class RolsterArrayGroup extends BaseArrayGroup {
207
+ constructor(options) {
208
+ const { controls, validators } = options;
209
+ const errors = validators ? helpers.groupIsValid({ controls, validators }) : [];
210
+ super({
211
+ ...options,
212
+ errors,
213
+ value: helpers.controlsToValue(controls),
214
+ dirties: helpers.controlsAllChecked(controls, 'dirty'),
215
+ dirty: helpers.controlsPartialChecked(controls, 'dirty'),
216
+ touched: helpers.controlsPartialChecked(controls, 'touched'),
217
+ toucheds: helpers.controlsAllChecked(controls, 'touched'),
218
+ valid: errors.length === 0 && helpers.controlsAllChecked(controls, 'valid')
219
+ });
150
220
  }
151
221
  }
152
222
  function formArrayGroup(options, validators) {
@@ -156,111 +226,102 @@ function formArrayGroup(options, validators) {
156
226
  });
157
227
  }
158
228
 
159
- class RolsterArrayList extends RolsterReactArrayControl {
229
+ class RolsterArrayList extends RolsterArrayControl {
160
230
  constructor(options) {
161
- const value = options.controls.map((controls) => helpers.controlsToValue(controls));
162
- super({ ...options, value });
163
- this.valueToControls = options.valueToControls;
164
- this.controls = options.controls;
231
+ const { controls, valueToControls, validators } = options;
232
+ const value = controls.map((controls) => helpers.controlsToValue(controls));
233
+ const errors = validators ? helpers.controlIsValid({ value, validators }) : [];
234
+ super({ ...options, errors, value });
235
+ this.valueToControls = valueToControls;
236
+ this.controls = controls;
165
237
  this.valid =
166
- this.errors.length === 0 &&
167
- this.controls.reduce((valid, controls) => valid && helpers.controlsAllChecked(controls, 'valid'), true);
238
+ errors.length === 0 &&
239
+ controls.reduce((valid, controls) => valid && helpers.controlsAllChecked(controls, 'valid'), true);
168
240
  this.invalid = !this.valid;
169
241
  this.wrong = this.touched && this.invalid;
170
- options.controls.forEach((controls) => {
171
- this.subscribeControls(controls);
242
+ controls.forEach((reactControls) => {
243
+ this._subscribe(reactControls);
172
244
  });
173
245
  }
174
246
  setValue(value) {
175
- this.refresh({
247
+ this.refresh('list', {
176
248
  controls: value.map((value) => this.valueToControls(value))
177
249
  });
178
250
  }
179
- clone(options) {
180
- return new RolsterArrayList(options);
181
- }
182
251
  push(controls) {
183
- this.refresh({
252
+ this.refresh('list', {
184
253
  controls: [...this.controls, controls]
185
254
  });
186
255
  }
187
256
  remove(controls) {
188
- this.refresh({
189
- controls: this.controls.filter((currentControls) => currentControls !== controls)
257
+ this.refresh('list', {
258
+ controls: this.controls.filter((_controls) => _controls !== controls)
259
+ });
260
+ }
261
+ builder(options) {
262
+ return new RolsterArrayList({
263
+ ...this,
264
+ ...options,
265
+ valueToControls: this.valueToControls
190
266
  });
191
267
  }
192
- refresh(changes) {
193
- super.refresh(changes);
268
+ refresh(action, options) {
269
+ super.refresh(action, options);
194
270
  }
195
- subscribeControls(newControls) {
196
- Object.values(newControls).forEach((control) => {
197
- control.subscribe((options) => {
198
- const controls = this.controls.map((_controls) => _controls !== newControls
271
+ _subscribe(reactControls) {
272
+ Object.values(reactControls).forEach((control) => {
273
+ control.subscribe((action, _control) => {
274
+ const _reactControls = this.controls.map((_controls) => reactControls !== _controls
199
275
  ? _controls
200
- : Object.entries(newControls).reduce((controls, [key, control]) => {
201
- controls[key] =
202
- control.uuid === options.uuid
203
- ? control.clone(options)
204
- : control;
205
- return controls;
206
- }, {}));
207
- this.refresh({ controls });
276
+ : replaceControl(reactControls, _control));
277
+ this.refresh(action, { controls: _reactControls });
208
278
  });
209
279
  });
210
280
  }
211
281
  }
212
- function formArrayList(valueToControls, options) {
282
+ function formArrayList(options) {
213
283
  const value = options?.value || [];
214
284
  return new RolsterArrayList({
215
285
  ...options,
216
- valueToControls,
217
- controls: value.map((value) => valueToControls(value)),
286
+ controls: value.map((value) => options.valueToControls(value)),
218
287
  initialValue: value,
219
288
  uuid: uuid.v4()
220
289
  });
221
290
  }
222
291
 
223
- var Language;
224
- (function (Language) {
225
- Language["English"] = "en";
226
- Language["French"] = "fr";
227
- Language["Portuguese"] = "pt";
228
- Language["Spanish"] = "es";
229
- })(Language || (Language = {}));
230
-
231
- Language.Spanish;
232
- let subscribers = [];
233
- function i18nSubscribe(subscriber) {
234
- subscribers.push(subscriber);
235
- return () => {
236
- subscribers = subscribers.filter((currentSubscriber) => subscriber !== currentSubscriber);
237
- };
238
- }
239
-
240
- function errorsInArray(groups, validators) {
241
- return validators ? helpers.arrayIsValid({ groups, validators }) : [];
242
- }
243
- function validStateInArray(groups, validators) {
244
- const errors = errorsInArray(groups, validators);
292
+ function refactorForValid$1(groups, validators) {
293
+ const errors = validators ? helpers.arrayIsValid({ groups, validators }) : [];
245
294
  return {
246
295
  errors,
247
296
  valid: errors.length === 0 && helpers.groupAllChecked(groups, 'valid')
248
297
  };
249
298
  }
250
- function replaceStateInArray(groups, validators) {
299
+ function refactorForGroups(groups, validators) {
251
300
  return {
252
- ...validStateInArray(groups, validators),
301
+ ...refactorForValid$1(groups, validators),
253
302
  groups,
254
303
  controls: groups.map(({ controls }) => controls),
255
304
  value: groups.map(({ controls }) => helpers.controlsToValue(controls))
256
305
  };
257
306
  }
307
+ function refactorForControls(state, groups, action) {
308
+ switch (action) {
309
+ case 'validators':
310
+ return refactorForValid$1(groups, state.validators);
311
+ case 'reset':
312
+ case 'list':
313
+ case 'value':
314
+ return refactorForGroups(groups, state.validators);
315
+ default:
316
+ return { groups };
317
+ }
318
+ }
258
319
  function useFormArray(options, validators) {
259
320
  const _options = _arguments.createFormArrayOptions(options, validators);
260
321
  const groups = _options.groups || [];
261
322
  const initialValue = react.useRef(groups);
262
323
  const [state, setState] = react.useState({
263
- ...validStateInArray(groups, _options.validators),
324
+ ...refactorForValid$1(groups, _options.validators),
264
325
  controls: groups.map(({ controls }) => controls),
265
326
  dirty: false,
266
327
  dirties: false,
@@ -272,21 +333,14 @@ function useFormArray(options, validators) {
272
333
  validators: _options.validators
273
334
  });
274
335
  react.useEffect(() => {
275
- return i18nSubscribe(() => {
276
- setState((state) => ({
277
- ...state,
278
- errors: errorsInArray(state.groups, state.validators)
279
- }));
280
- });
281
- }, []);
282
- react.useEffect(() => {
283
- const subscriber = (options) => {
284
- setState((state) => ({
285
- ...state,
286
- ...replaceStateInArray(state.groups.map((group) => group.uuid === options.uuid
287
- ? new RolsterArrayGroup(options)
288
- : group), state.validators)
289
- }));
336
+ const subscriber = (action, group) => {
337
+ setState((state) => {
338
+ const groups = state.groups.map((_group) => _group.uuid === group.uuid ? group : _group);
339
+ return {
340
+ ...state,
341
+ ...refactorForControls(state, groups, action)
342
+ };
343
+ });
290
344
  };
291
345
  state.groups.forEach((group) => {
292
346
  group.subscribe(subscriber);
@@ -301,49 +355,49 @@ function useFormArray(options, validators) {
301
355
  const setValue = react.useCallback((groups) => {
302
356
  setState((state) => ({
303
357
  ...state,
304
- ...replaceStateInArray(groups, state.validators)
358
+ ...refactorForGroups(groups, state.validators)
305
359
  }));
306
360
  }, []);
307
361
  const setInitialValue = react.useCallback((groups) => {
308
362
  setState((state) => ({
309
363
  ...state,
310
- ...replaceStateInArray(groups, state.validators)
364
+ ...refactorForGroups(groups, state.validators)
311
365
  }));
312
366
  initialValue.current = groups;
313
367
  }, []);
314
368
  const push = react.useCallback((group) => {
315
369
  setState((state) => ({
316
370
  ...state,
317
- ...replaceStateInArray([...state.groups, group], state.validators)
371
+ ...refactorForGroups([...state.groups, group], state.validators)
318
372
  }));
319
373
  }, []);
320
374
  const merge = react.useCallback((groups) => {
321
375
  setState((state) => ({
322
376
  ...state,
323
- ...replaceStateInArray([...state.groups, ...groups], state.validators)
377
+ ...refactorForGroups([...state.groups, ...groups], state.validators)
324
378
  }));
325
379
  }, []);
326
380
  const remove = react.useCallback(({ uuid }) => {
327
381
  setState((state) => ({
328
382
  ...state,
329
- ...replaceStateInArray(state.groups.filter((group) => group.uuid !== uuid), state.validators)
330
- }));
331
- }, []);
332
- const reset = react.useCallback(() => {
333
- setState((state) => ({
334
- ...state,
335
- ...replaceStateInArray(initialValue.current, state.validators)
383
+ ...refactorForGroups(state.groups.filter((group) => group.uuid !== uuid), state.validators)
336
384
  }));
337
385
  }, []);
338
386
  const setValidators = react.useCallback((validators) => {
339
387
  setState((state) => ({
340
388
  ...state,
341
- ...validStateInArray(state.groups, validators),
389
+ ...refactorForValid$1(state.groups, validators),
342
390
  validators
343
391
  }));
344
392
  }, []);
345
393
  const hasError = react.useCallback((key) => helpers.hasError(state.errors, key), [state.errors]);
346
394
  const someErrors = react.useCallback((keys) => helpers.someErrors(state.errors, keys), [state.errors]);
395
+ const reset = react.useCallback(() => {
396
+ setState((state) => ({
397
+ ...state,
398
+ ...refactorForGroups(initialValue.current, state.validators)
399
+ }));
400
+ }, []);
347
401
  return {
348
402
  ...state,
349
403
  disable,
@@ -384,14 +438,6 @@ function useControl(options, validators) {
384
438
  validators: _options.validators
385
439
  });
386
440
  const elementRef = react.useRef(null);
387
- react.useEffect(() => {
388
- return i18nSubscribe(() => {
389
- setState((state) => ({
390
- ...state,
391
- errors: errorsInControl(state.value, state.validators)
392
- }));
393
- });
394
- }, []);
395
441
  const focus = react.useCallback(() => {
396
442
  setState((state) => ({ ...state, focused: true }));
397
443
  }, []);
@@ -477,11 +523,8 @@ function useInputControl(options, validators) {
477
523
  return useControl(options, validators);
478
524
  }
479
525
 
480
- function errorsInGroup(controls, validators) {
481
- return validators ? helpers.groupIsValid({ controls, validators }) : [];
482
- }
483
- function validStateInGroup(controls, validators) {
484
- const errors = errorsInGroup(controls, validators);
526
+ function refactorForValid(controls, validators) {
527
+ const errors = validators ? helpers.groupIsValid({ controls, validators }) : [];
485
528
  return {
486
529
  errors,
487
530
  valid: errors.length === 0 && helpers.controlsAllChecked(controls, 'valid')
@@ -490,8 +533,14 @@ function validStateInGroup(controls, validators) {
490
533
  function useFormGroup(options, validators) {
491
534
  const _options = _arguments.createFormGroupOptions(options, validators);
492
535
  const { controls } = _options;
536
+ const firstEffects = react.useRef({
537
+ dirty: true,
538
+ disabledFocused: true,
539
+ touched: true,
540
+ value: true
541
+ });
493
542
  const [state, setState] = react.useState({
494
- ...validStateInGroup(controls, _options.validators),
543
+ ...refactorForValid(controls, _options.validators),
495
544
  controls,
496
545
  dirties: helpers.controlsAllChecked(controls, 'dirty'),
497
546
  dirty: helpers.controlsPartialChecked(controls, 'dirty'),
@@ -501,50 +550,62 @@ function useFormGroup(options, validators) {
501
550
  validators: _options.validators
502
551
  });
503
552
  react.useEffect(() => {
504
- return i18nSubscribe(() => {
553
+ if (!firstEffects.current.value) {
505
554
  setState((state) => ({
506
555
  ...state,
507
- errors: errorsInGroup(state.controls, state.validators)
556
+ ...refactorForValid(controls, state.validators),
557
+ controls,
558
+ value: helpers.controlsToValue(controls)
508
559
  }));
509
- });
510
- }, []);
511
- react.useEffect(() => {
512
- setState((state) => ({
513
- ...state,
514
- ...validStateInGroup(controls, state.validators),
515
- controls,
516
- value: helpers.controlsToValue(controls)
517
- }));
560
+ }
561
+ else {
562
+ firstEffects.current.value = false;
563
+ }
518
564
  }, helpers.reduceControlsToArray(controls, 'value'));
519
565
  react.useEffect(() => {
520
- setState((state) => ({
521
- ...state,
522
- controls
523
- }));
566
+ if (!firstEffects.current.disabledFocused) {
567
+ setState((state) => ({
568
+ ...state,
569
+ controls
570
+ }));
571
+ }
572
+ else {
573
+ firstEffects.current.disabledFocused = false;
574
+ }
524
575
  }, [
525
576
  ...helpers.reduceControlsToArray(controls, 'disabled'),
526
577
  ...helpers.reduceControlsToArray(controls, 'focused')
527
578
  ]);
528
579
  react.useEffect(() => {
529
- setState((state) => ({
530
- ...state,
531
- controls,
532
- dirty: helpers.controlsPartialChecked(controls, 'dirty'),
533
- dirties: helpers.controlsAllChecked(controls, 'dirty')
534
- }));
580
+ if (!firstEffects.current.dirty) {
581
+ setState((state) => ({
582
+ ...state,
583
+ controls,
584
+ dirty: helpers.controlsPartialChecked(controls, 'dirty'),
585
+ dirties: helpers.controlsAllChecked(controls, 'dirty')
586
+ }));
587
+ }
588
+ else {
589
+ firstEffects.current.dirty = false;
590
+ }
535
591
  }, helpers.reduceControlsToArray(controls, 'dirty'));
536
592
  react.useEffect(() => {
537
- setState((state) => ({
538
- ...state,
539
- controls,
540
- touched: helpers.controlsPartialChecked(controls, 'touched'),
541
- toucheds: helpers.controlsAllChecked(controls, 'touched')
542
- }));
593
+ if (!firstEffects.current.touched) {
594
+ setState((state) => ({
595
+ ...state,
596
+ controls,
597
+ touched: helpers.controlsPartialChecked(controls, 'touched'),
598
+ toucheds: helpers.controlsAllChecked(controls, 'touched')
599
+ }));
600
+ }
601
+ else {
602
+ firstEffects.current.touched = false;
603
+ }
543
604
  }, helpers.reduceControlsToArray(controls, 'touched'));
544
605
  const setValidators = react.useCallback((validators) => {
545
606
  setState((state) => ({
546
607
  ...state,
547
- ...validStateInGroup(state.controls, validators)
608
+ ...refactorForValid(state.controls, validators)
548
609
  }));
549
610
  }, []);
550
611
  const reset = react.useCallback(() => {