@rolster/react-forms 18.11.4 → 18.12.1

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,113 @@ 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);
244
+ });
245
+ }
246
+ setInitialValue(value) {
247
+ this.refresh('list', {
248
+ controls: value.map((value) => this.valueToControls(value)),
249
+ initialValue: value
172
250
  });
173
251
  }
174
252
  setValue(value) {
175
- this.refresh({
253
+ this.refresh('list', {
176
254
  controls: value.map((value) => this.valueToControls(value))
177
255
  });
178
256
  }
179
- clone(options) {
180
- return new RolsterArrayList(options);
257
+ reset() {
258
+ this.refresh('list', {
259
+ controls: this.initialValue.map((value) => this.valueToControls(value))
260
+ });
181
261
  }
182
262
  push(controls) {
183
- this.refresh({
263
+ this.refresh('list', {
184
264
  controls: [...this.controls, controls]
185
265
  });
186
266
  }
187
267
  remove(controls) {
188
- this.refresh({
189
- controls: this.controls.filter((currentControls) => currentControls !== controls)
268
+ this.refresh('list', {
269
+ controls: this.controls.filter((_controls) => _controls !== controls)
190
270
  });
191
271
  }
192
- refresh(changes) {
193
- super.refresh(changes);
272
+ builder(options) {
273
+ return new RolsterArrayList({
274
+ ...this,
275
+ ...options,
276
+ valueToControls: this.valueToControls
277
+ });
194
278
  }
195
- subscribeControls(newControls) {
196
- Object.values(newControls).forEach((control) => {
197
- control.subscribe((options) => {
198
- const controls = this.controls.map((_controls) => _controls !== newControls
279
+ refresh(action, options) {
280
+ super.refresh(action, options);
281
+ }
282
+ _subscribe(reactControls) {
283
+ Object.values(reactControls).forEach((control) => {
284
+ control.subscribe((action, _control) => {
285
+ const _reactControls = this.controls.map((_controls) => reactControls !== _controls
199
286
  ? _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 });
287
+ : replaceControl(reactControls, _control));
288
+ this.refresh(action, { controls: _reactControls });
208
289
  });
209
290
  });
210
291
  }
211
292
  }
212
- function formArrayList(valueToControls, options) {
293
+ function formArrayList(options) {
213
294
  const value = options?.value || [];
214
295
  return new RolsterArrayList({
215
296
  ...options,
216
- valueToControls,
217
- controls: value.map((value) => valueToControls(value)),
297
+ controls: value.map((value) => options.valueToControls(value)),
218
298
  initialValue: value,
219
299
  uuid: uuid.v4()
220
300
  });
221
301
  }
222
302
 
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);
303
+ function refactorForValid$1(groups, validators) {
304
+ const errors = validators ? helpers.arrayIsValid({ groups, validators }) : [];
245
305
  return {
246
306
  errors,
247
307
  valid: errors.length === 0 && helpers.groupAllChecked(groups, 'valid')
248
308
  };
249
309
  }
250
- function replaceStateInArray(groups, validators) {
310
+ function refactorForGroups(groups, validators) {
251
311
  return {
252
- ...validStateInArray(groups, validators),
312
+ ...refactorForValid$1(groups, validators),
253
313
  groups,
254
314
  controls: groups.map(({ controls }) => controls),
255
315
  value: groups.map(({ controls }) => helpers.controlsToValue(controls))
256
316
  };
257
317
  }
318
+ function refactorForControls(state, groups, action) {
319
+ switch (action) {
320
+ case 'validators':
321
+ return refactorForValid$1(groups, state.validators);
322
+ case 'reset':
323
+ case 'list':
324
+ case 'value':
325
+ return refactorForGroups(groups, state.validators);
326
+ default:
327
+ return { groups };
328
+ }
329
+ }
258
330
  function useFormArray(options, validators) {
259
331
  const _options = _arguments.createFormArrayOptions(options, validators);
260
332
  const groups = _options.groups || [];
261
333
  const initialValue = react.useRef(groups);
262
334
  const [state, setState] = react.useState({
263
- ...validStateInArray(groups, _options.validators),
335
+ ...refactorForValid$1(groups, _options.validators),
264
336
  controls: groups.map(({ controls }) => controls),
265
337
  dirty: false,
266
338
  dirties: false,
@@ -272,21 +344,14 @@ function useFormArray(options, validators) {
272
344
  validators: _options.validators
273
345
  });
274
346
  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
- }));
347
+ const subscriber = (action, group) => {
348
+ setState((state) => {
349
+ const groups = state.groups.map((_group) => _group.uuid === group.uuid ? group : _group);
350
+ return {
351
+ ...state,
352
+ ...refactorForControls(state, groups, action)
353
+ };
354
+ });
290
355
  };
291
356
  state.groups.forEach((group) => {
292
357
  group.subscribe(subscriber);
@@ -301,49 +366,49 @@ function useFormArray(options, validators) {
301
366
  const setValue = react.useCallback((groups) => {
302
367
  setState((state) => ({
303
368
  ...state,
304
- ...replaceStateInArray(groups, state.validators)
369
+ ...refactorForGroups(groups, state.validators)
305
370
  }));
306
371
  }, []);
307
372
  const setInitialValue = react.useCallback((groups) => {
308
373
  setState((state) => ({
309
374
  ...state,
310
- ...replaceStateInArray(groups, state.validators)
375
+ ...refactorForGroups(groups, state.validators)
311
376
  }));
312
377
  initialValue.current = groups;
313
378
  }, []);
314
379
  const push = react.useCallback((group) => {
315
380
  setState((state) => ({
316
381
  ...state,
317
- ...replaceStateInArray([...state.groups, group], state.validators)
382
+ ...refactorForGroups([...state.groups, group], state.validators)
318
383
  }));
319
384
  }, []);
320
385
  const merge = react.useCallback((groups) => {
321
386
  setState((state) => ({
322
387
  ...state,
323
- ...replaceStateInArray([...state.groups, ...groups], state.validators)
388
+ ...refactorForGroups([...state.groups, ...groups], state.validators)
324
389
  }));
325
390
  }, []);
326
391
  const remove = react.useCallback(({ uuid }) => {
327
392
  setState((state) => ({
328
393
  ...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)
394
+ ...refactorForGroups(state.groups.filter((group) => group.uuid !== uuid), state.validators)
336
395
  }));
337
396
  }, []);
338
397
  const setValidators = react.useCallback((validators) => {
339
398
  setState((state) => ({
340
399
  ...state,
341
- ...validStateInArray(state.groups, validators),
400
+ ...refactorForValid$1(state.groups, validators),
342
401
  validators
343
402
  }));
344
403
  }, []);
345
404
  const hasError = react.useCallback((key) => helpers.hasError(state.errors, key), [state.errors]);
346
405
  const someErrors = react.useCallback((keys) => helpers.someErrors(state.errors, keys), [state.errors]);
406
+ const reset = react.useCallback(() => {
407
+ setState((state) => ({
408
+ ...state,
409
+ ...refactorForGroups(initialValue.current, state.validators)
410
+ }));
411
+ }, []);
347
412
  return {
348
413
  ...state,
349
414
  disable,
@@ -384,14 +449,6 @@ function useControl(options, validators) {
384
449
  validators: _options.validators
385
450
  });
386
451
  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
452
  const focus = react.useCallback(() => {
396
453
  setState((state) => ({ ...state, focused: true }));
397
454
  }, []);
@@ -477,11 +534,8 @@ function useInputControl(options, validators) {
477
534
  return useControl(options, validators);
478
535
  }
479
536
 
480
- function errorsInGroup(controls, validators) {
481
- return validators ? helpers.groupIsValid({ controls, validators }) : [];
482
- }
483
- function validStateInGroup(controls, validators) {
484
- const errors = errorsInGroup(controls, validators);
537
+ function refactorForValid(controls, validators) {
538
+ const errors = validators ? helpers.groupIsValid({ controls, validators }) : [];
485
539
  return {
486
540
  errors,
487
541
  valid: errors.length === 0 && helpers.controlsAllChecked(controls, 'valid')
@@ -490,8 +544,14 @@ function validStateInGroup(controls, validators) {
490
544
  function useFormGroup(options, validators) {
491
545
  const _options = _arguments.createFormGroupOptions(options, validators);
492
546
  const { controls } = _options;
547
+ const firstEffects = react.useRef({
548
+ dirty: true,
549
+ disabledFocused: true,
550
+ touched: true,
551
+ value: true
552
+ });
493
553
  const [state, setState] = react.useState({
494
- ...validStateInGroup(controls, _options.validators),
554
+ ...refactorForValid(controls, _options.validators),
495
555
  controls,
496
556
  dirties: helpers.controlsAllChecked(controls, 'dirty'),
497
557
  dirty: helpers.controlsPartialChecked(controls, 'dirty'),
@@ -501,50 +561,62 @@ function useFormGroup(options, validators) {
501
561
  validators: _options.validators
502
562
  });
503
563
  react.useEffect(() => {
504
- return i18nSubscribe(() => {
564
+ if (!firstEffects.current.value) {
505
565
  setState((state) => ({
506
566
  ...state,
507
- errors: errorsInGroup(state.controls, state.validators)
567
+ ...refactorForValid(controls, state.validators),
568
+ controls,
569
+ value: helpers.controlsToValue(controls)
508
570
  }));
509
- });
510
- }, []);
511
- react.useEffect(() => {
512
- setState((state) => ({
513
- ...state,
514
- ...validStateInGroup(controls, state.validators),
515
- controls,
516
- value: helpers.controlsToValue(controls)
517
- }));
571
+ }
572
+ else {
573
+ firstEffects.current.value = false;
574
+ }
518
575
  }, helpers.reduceControlsToArray(controls, 'value'));
519
576
  react.useEffect(() => {
520
- setState((state) => ({
521
- ...state,
522
- controls
523
- }));
577
+ if (!firstEffects.current.disabledFocused) {
578
+ setState((state) => ({
579
+ ...state,
580
+ controls
581
+ }));
582
+ }
583
+ else {
584
+ firstEffects.current.disabledFocused = false;
585
+ }
524
586
  }, [
525
587
  ...helpers.reduceControlsToArray(controls, 'disabled'),
526
588
  ...helpers.reduceControlsToArray(controls, 'focused')
527
589
  ]);
528
590
  react.useEffect(() => {
529
- setState((state) => ({
530
- ...state,
531
- controls,
532
- dirty: helpers.controlsPartialChecked(controls, 'dirty'),
533
- dirties: helpers.controlsAllChecked(controls, 'dirty')
534
- }));
591
+ if (!firstEffects.current.dirty) {
592
+ setState((state) => ({
593
+ ...state,
594
+ controls,
595
+ dirty: helpers.controlsPartialChecked(controls, 'dirty'),
596
+ dirties: helpers.controlsAllChecked(controls, 'dirty')
597
+ }));
598
+ }
599
+ else {
600
+ firstEffects.current.dirty = false;
601
+ }
535
602
  }, helpers.reduceControlsToArray(controls, 'dirty'));
536
603
  react.useEffect(() => {
537
- setState((state) => ({
538
- ...state,
539
- controls,
540
- touched: helpers.controlsPartialChecked(controls, 'touched'),
541
- toucheds: helpers.controlsAllChecked(controls, 'touched')
542
- }));
604
+ if (!firstEffects.current.touched) {
605
+ setState((state) => ({
606
+ ...state,
607
+ controls,
608
+ touched: helpers.controlsPartialChecked(controls, 'touched'),
609
+ toucheds: helpers.controlsAllChecked(controls, 'touched')
610
+ }));
611
+ }
612
+ else {
613
+ firstEffects.current.touched = false;
614
+ }
543
615
  }, helpers.reduceControlsToArray(controls, 'touched'));
544
616
  const setValidators = react.useCallback((validators) => {
545
617
  setState((state) => ({
546
618
  ...state,
547
- ...validStateInGroup(state.controls, validators)
619
+ ...refactorForValid(state.controls, validators)
548
620
  }));
549
621
  }, []);
550
622
  const reset = react.useCallback(() => {