mobx-form 13.2.0 → 13.3.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.
@@ -100,6 +100,10 @@ const isNullishOrEmpty = value => typeof value === 'undefined' || value === null
100
100
 
101
101
 
102
102
  class Field {
103
+ get validatedAtLeastOnce() {
104
+ return this._validatedOnce;
105
+ }
106
+
103
107
  get waitForBlur() {
104
108
  return !!this._waitForBlur;
105
109
  }
@@ -121,6 +125,10 @@ class Field {
121
125
  this._interacted = true;
122
126
  }
123
127
 
128
+ resetValidatedOnce() {
129
+ this._validatedOnce = false;
130
+ }
131
+
124
132
  get hasValue() {
125
133
  if (this._hasValueFn) {
126
134
  return this._hasValueFn(this.value);
@@ -359,6 +367,11 @@ class Field {
359
367
  const {
360
368
  required
361
369
  } = this;
370
+
371
+ if (!this._validatedOnce) {
372
+ this._validatedOnce = true;
373
+ }
374
+
362
375
  const shouldSkipValidation = this.disabled || !required && !this._validateFn;
363
376
  if (shouldSkipValidation) return;
364
377
 
@@ -477,6 +490,7 @@ class Field {
477
490
  constructor(model, value, validatorDescriptor = {}, fieldName) {
478
491
  this._disabled = void 0;
479
492
  this._required = void 0;
493
+ this._validatedOnce = false;
480
494
  this._validating = false;
481
495
  this._initialValue = void 0;
482
496
  this._value = void 0;
@@ -509,6 +523,9 @@ class Field {
509
523
  };
510
524
 
511
525
  mobx.makeObservable(this, {
526
+ resetValidatedOnce: mobx.action,
527
+ _validatedOnce: mobx.observable,
528
+ validatedAtLeastOnce: mobx.computed,
512
529
  _disabled: mobx.observable,
513
530
  _required: mobx.observable,
514
531
  waitForBlur: mobx.computed,
@@ -594,6 +611,11 @@ const isObject = o => o && toString.call(o) === '[object Object]';
594
611
 
595
612
 
596
613
  class FormModel {
614
+ get validatedAtLeastOnce() {
615
+ const keys = Object.keys(this.fields);
616
+ return keys.every(key => this.fields[key].validatedAtLeastOnce);
617
+ }
618
+
597
619
  get dataIsReady() {
598
620
  return this.interacted && this.requiredAreFilled && this.valid;
599
621
  }
@@ -810,6 +832,8 @@ class FormModel {
810
832
  };
811
833
 
812
834
  mobx.makeObservable(this, {
835
+ resetValidatedOnce: mobx.action,
836
+ validatedAtLeastOnce: mobx.computed,
813
837
  dataIsReady: mobx.computed,
814
838
  requiredFields: mobx.computed,
815
839
  requiredAreFilled: mobx.computed,
@@ -888,6 +912,12 @@ class FormModel {
888
912
  });
889
913
  }
890
914
 
915
+ resetValidatedOnce() {
916
+ this._fieldKeys().forEach(key => {
917
+ this.fields[key].resetValidatedOnce();
918
+ });
919
+ }
920
+
891
921
  }
892
922
  /**
893
923
  * return an instance of a FormModel refer to the constructor
@@ -94,6 +94,10 @@ const isNullishOrEmpty = value => typeof value === 'undefined' || value === null
94
94
 
95
95
 
96
96
  class Field {
97
+ get validatedAtLeastOnce() {
98
+ return this._validatedOnce;
99
+ }
100
+
97
101
  get waitForBlur() {
98
102
  return !!this._waitForBlur;
99
103
  }
@@ -115,6 +119,10 @@ class Field {
115
119
  this._interacted = true;
116
120
  }
117
121
 
122
+ resetValidatedOnce() {
123
+ this._validatedOnce = false;
124
+ }
125
+
118
126
  get hasValue() {
119
127
  if (this._hasValueFn) {
120
128
  return this._hasValueFn(this.value);
@@ -353,6 +361,11 @@ class Field {
353
361
  const {
354
362
  required
355
363
  } = this;
364
+
365
+ if (!this._validatedOnce) {
366
+ this._validatedOnce = true;
367
+ }
368
+
356
369
  const shouldSkipValidation = this.disabled || !required && !this._validateFn;
357
370
  if (shouldSkipValidation) return;
358
371
 
@@ -471,6 +484,7 @@ class Field {
471
484
  constructor(model, value, validatorDescriptor = {}, fieldName) {
472
485
  this._disabled = void 0;
473
486
  this._required = void 0;
487
+ this._validatedOnce = false;
474
488
  this._validating = false;
475
489
  this._initialValue = void 0;
476
490
  this._value = void 0;
@@ -503,6 +517,9 @@ class Field {
503
517
  };
504
518
 
505
519
  makeObservable(this, {
520
+ resetValidatedOnce: action,
521
+ _validatedOnce: observable,
522
+ validatedAtLeastOnce: computed,
506
523
  _disabled: observable,
507
524
  _required: observable,
508
525
  waitForBlur: computed,
@@ -588,6 +605,11 @@ const isObject = o => o && toString.call(o) === '[object Object]';
588
605
 
589
606
 
590
607
  class FormModel {
608
+ get validatedAtLeastOnce() {
609
+ const keys = Object.keys(this.fields);
610
+ return keys.every(key => this.fields[key].validatedAtLeastOnce);
611
+ }
612
+
591
613
  get dataIsReady() {
592
614
  return this.interacted && this.requiredAreFilled && this.valid;
593
615
  }
@@ -804,6 +826,8 @@ class FormModel {
804
826
  };
805
827
 
806
828
  makeObservable(this, {
829
+ resetValidatedOnce: action,
830
+ validatedAtLeastOnce: computed,
807
831
  dataIsReady: computed,
808
832
  requiredFields: computed,
809
833
  requiredAreFilled: computed,
@@ -882,6 +906,12 @@ class FormModel {
882
906
  });
883
907
  }
884
908
 
909
+ resetValidatedOnce() {
910
+ this._fieldKeys().forEach(key => {
911
+ this.fields[key].resetValidatedOnce();
912
+ });
913
+ }
914
+
885
915
  }
886
916
  /**
887
917
  * return an instance of a FormModel refer to the constructor
@@ -203,6 +203,11 @@ var Field = /*#__PURE__*/function () {
203
203
  value: function markAsInteracted() {
204
204
  this._interacted = true;
205
205
  }
206
+ }, {
207
+ key: "resetValidatedOnce",
208
+ value: function resetValidatedOnce() {
209
+ this._validatedOnce = false;
210
+ }
206
211
  }, {
207
212
  key: "_setValueOnly",
208
213
  value: function _setValueOnly(val) {
@@ -434,6 +439,11 @@ var Field = /*#__PURE__*/function () {
434
439
  force = _ref3$force === void 0 ? false : _ref3$force;
435
440
 
436
441
  var required = this.required;
442
+
443
+ if (!this._validatedOnce) {
444
+ this._validatedOnce = true;
445
+ }
446
+
437
447
  var shouldSkipValidation = this.disabled || !required && !this._validateFn;
438
448
  if (shouldSkipValidation) return;
439
449
 
@@ -551,6 +561,11 @@ var Field = /*#__PURE__*/function () {
551
561
  value: function setError(error) {
552
562
  this.rawError = error;
553
563
  }
564
+ }, {
565
+ key: "validatedAtLeastOnce",
566
+ get: function get() {
567
+ return this._validatedOnce;
568
+ }
554
569
  }, {
555
570
  key: "waitForBlur",
556
571
  get: function get() {
@@ -680,6 +695,7 @@ var Field = /*#__PURE__*/function () {
680
695
 
681
696
  this._disabled = void 0;
682
697
  this._required = void 0;
698
+ this._validatedOnce = false;
683
699
  this._validating = false;
684
700
  this._initialValue = void 0;
685
701
  this._value = void 0;
@@ -712,6 +728,9 @@ var Field = /*#__PURE__*/function () {
712
728
  };
713
729
 
714
730
  mobx.makeObservable(this, {
731
+ resetValidatedOnce: mobx.action,
732
+ _validatedOnce: mobx.observable,
733
+ validatedAtLeastOnce: mobx.computed,
715
734
  _disabled: mobx.observable,
716
735
  _required: mobx.observable,
717
736
  waitForBlur: mobx.computed,
@@ -884,6 +903,16 @@ var FormModel = /*#__PURE__*/function () {
884
903
  * return the data as plain Javascript object (mobx magic removed from the fields)
885
904
  * */
886
905
 
906
+ }, {
907
+ key: "validatedAtLeastOnce",
908
+ get: function get() {
909
+ var _this3 = this;
910
+
911
+ var keys = Object.keys(this.fields);
912
+ return keys.every(function (key) {
913
+ return _this3.fields[key].validatedAtLeastOnce;
914
+ });
915
+ }
887
916
  }, {
888
917
  key: "dataIsReady",
889
918
  get: function get() {
@@ -892,21 +921,21 @@ var FormModel = /*#__PURE__*/function () {
892
921
  }, {
893
922
  key: "requiredFields",
894
923
  get: function get() {
895
- var _this3 = this;
924
+ var _this4 = this;
896
925
 
897
926
  var keys = Object.keys(this.fields);
898
927
  return keys.filter(function (key) {
899
- return _this3.fields[key].required;
928
+ return _this4.fields[key].required;
900
929
  });
901
930
  }
902
931
  }, {
903
932
  key: "requiredAreFilled",
904
933
  get: function get() {
905
- var _this4 = this;
934
+ var _this5 = this;
906
935
 
907
936
  var keys = Object.keys(this.fields);
908
937
  return keys.every(function (key) {
909
- var field = _this4.fields[key];
938
+ var field = _this5.fields[key];
910
939
 
911
940
  if (field.required) {
912
941
  return !!field.hasValue;
@@ -921,7 +950,7 @@ var FormModel = /*#__PURE__*/function () {
921
950
  // since some of the validators might be async validators
922
951
  // this value might be false until the validation process finish
923
952
  get: function get() {
924
- var _this5 = this;
953
+ var _this6 = this;
925
954
 
926
955
  if (this._validating) {
927
956
  return false; // consider the form invalid until the validation process finish
@@ -929,7 +958,7 @@ var FormModel = /*#__PURE__*/function () {
929
958
 
930
959
  var keys = Object.keys(this.fields);
931
960
  return keys.every(function (key) {
932
- var field = _this5.fields[key];
961
+ var field = _this6.fields[key];
933
962
  return !!field.valid;
934
963
  });
935
964
  }
@@ -942,22 +971,22 @@ var FormModel = /*#__PURE__*/function () {
942
971
  }, {
943
972
  key: "interacted",
944
973
  get: function get() {
945
- var _this6 = this;
974
+ var _this7 = this;
946
975
 
947
976
  var keys = this._fieldKeys();
948
977
 
949
978
  return keys.some(function (key) {
950
- var field = _this6.fields[key];
979
+ var field = _this7.fields[key];
951
980
  return !!field.interacted;
952
981
  });
953
982
  }
954
983
  }, {
955
984
  key: "summary",
956
985
  get: function get() {
957
- var _this7 = this;
986
+ var _this8 = this;
958
987
 
959
988
  return this._fieldKeys().reduce(function (seq, key) {
960
- var field = _this7.fields[key];
989
+ var field = _this8.fields[key];
961
990
 
962
991
  if (field.errorMessage) {
963
992
  seq.push(field.errorMessage);
@@ -969,10 +998,10 @@ var FormModel = /*#__PURE__*/function () {
969
998
  }, {
970
999
  key: "validating",
971
1000
  get: function get() {
972
- var _this8 = this;
1001
+ var _this9 = this;
973
1002
 
974
1003
  return this._validating || this._fieldKeys().some(function (key) {
975
- var f = _this8._getField(key);
1004
+ var f = _this9._getField(key);
976
1005
 
977
1006
  return f.validating;
978
1007
  });
@@ -980,11 +1009,11 @@ var FormModel = /*#__PURE__*/function () {
980
1009
  }, {
981
1010
  key: "serializedData",
982
1011
  get: function get() {
983
- var _this9 = this;
1012
+ var _this10 = this;
984
1013
 
985
1014
  var keys = Object.keys(this.fields);
986
1015
  return mobx.toJS(keys.reduce(function (seq, key) {
987
- var field = _this9.fields[key];
1016
+ var field = _this10.fields[key];
988
1017
  var value = mobx.toJS(field.value); // this is required to make sure forms that use the serializedData object
989
1018
  // have the values without leading or trailing spaces
990
1019
 
@@ -1005,7 +1034,7 @@ var FormModel = /*#__PURE__*/function () {
1005
1034
  }]);
1006
1035
 
1007
1036
  function FormModel() {
1008
- var _this10 = this;
1037
+ var _this11 = this;
1009
1038
 
1010
1039
  var _ref2 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
1011
1040
  _ref2$descriptors = _ref2.descriptors,
@@ -1020,7 +1049,7 @@ var FormModel = /*#__PURE__*/function () {
1020
1049
  this._validating = false;
1021
1050
 
1022
1051
  this.setValidating = function (validating) {
1023
- _this10._validating = validating;
1052
+ _this11._validating = validating;
1024
1053
  };
1025
1054
 
1026
1055
  this.addFields = function (fieldsDescriptor) {
@@ -1034,7 +1063,7 @@ var FormModel = /*#__PURE__*/function () {
1034
1063
  name = field.name,
1035
1064
  descriptor = _objectWithoutProperties(field, ["value", "name"]);
1036
1065
 
1037
- _this10._createField({
1066
+ _this11._createField({
1038
1067
  value: value,
1039
1068
  name: name,
1040
1069
  descriptor: descriptor
@@ -1049,7 +1078,7 @@ var FormModel = /*#__PURE__*/function () {
1049
1078
  value = _fieldsDescriptor$key.value,
1050
1079
  descriptor = _objectWithoutProperties(_fieldsDescriptor$key, ["value"]);
1051
1080
 
1052
- _this10._createField({
1081
+ _this11._createField({
1053
1082
  value: value,
1054
1083
  name: key,
1055
1084
  descriptor: descriptor
@@ -1058,6 +1087,8 @@ var FormModel = /*#__PURE__*/function () {
1058
1087
  };
1059
1088
 
1060
1089
  mobx.makeObservable(this, {
1090
+ resetValidatedOnce: mobx.action,
1091
+ validatedAtLeastOnce: mobx.computed,
1061
1092
  dataIsReady: mobx.computed,
1062
1093
  requiredFields: mobx.computed,
1063
1094
  requiredAreFilled: mobx.computed,
@@ -1102,10 +1133,10 @@ var FormModel = /*#__PURE__*/function () {
1102
1133
  }, {
1103
1134
  key: "_eachField",
1104
1135
  value: function _eachField(cb) {
1105
- var _this11 = this;
1136
+ var _this12 = this;
1106
1137
 
1107
1138
  Object.keys(this.fields).forEach(function (key) {
1108
- return cb(_this11.fields[key]);
1139
+ return cb(_this12.fields[key]);
1109
1140
  });
1110
1141
  }
1111
1142
  }, {
@@ -1123,11 +1154,11 @@ var FormModel = /*#__PURE__*/function () {
1123
1154
  }, {
1124
1155
  key: "disableFields",
1125
1156
  value: function disableFields(fieldKeys) {
1126
- var _this12 = this;
1157
+ var _this13 = this;
1127
1158
 
1128
1159
  if (!Array.isArray(fieldKeys)) throw new TypeError('fieldKeys should be an array with the names of the fields to disable');
1129
1160
  fieldKeys.forEach(function (key) {
1130
- var field = _this12._getField(key);
1161
+ var field = _this13._getField(key);
1131
1162
 
1132
1163
  field.setDisabled(true);
1133
1164
  });
@@ -1143,15 +1174,24 @@ var FormModel = /*#__PURE__*/function () {
1143
1174
  }, {
1144
1175
  key: "enableFields",
1145
1176
  value: function enableFields(fieldKeys) {
1146
- var _this13 = this;
1177
+ var _this14 = this;
1147
1178
 
1148
1179
  if (!Array.isArray(fieldKeys)) throw new TypeError('fieldKeys should be an array with the names of the fields to disable');
1149
1180
  fieldKeys.forEach(function (key) {
1150
- var field = _this13._getField(key);
1181
+ var field = _this14._getField(key);
1151
1182
 
1152
1183
  field.setDisabled(false);
1153
1184
  });
1154
1185
  }
1186
+ }, {
1187
+ key: "resetValidatedOnce",
1188
+ value: function resetValidatedOnce() {
1189
+ var _this15 = this;
1190
+
1191
+ this._fieldKeys().forEach(function (key) {
1192
+ _this15.fields[key].resetValidatedOnce();
1193
+ });
1194
+ }
1155
1195
  }]);
1156
1196
 
1157
1197
  return FormModel;
@@ -263,6 +263,11 @@
263
263
  value: function markAsInteracted() {
264
264
  this._interacted = true;
265
265
  }
266
+ }, {
267
+ key: "resetValidatedOnce",
268
+ value: function resetValidatedOnce() {
269
+ this._validatedOnce = false;
270
+ }
266
271
  }, {
267
272
  key: "_setValueOnly",
268
273
  value: function _setValueOnly(val) {
@@ -494,6 +499,11 @@
494
499
  force = _ref3$force === void 0 ? false : _ref3$force;
495
500
 
496
501
  var required = this.required;
502
+
503
+ if (!this._validatedOnce) {
504
+ this._validatedOnce = true;
505
+ }
506
+
497
507
  var shouldSkipValidation = this.disabled || !required && !this._validateFn;
498
508
  if (shouldSkipValidation) return;
499
509
 
@@ -611,6 +621,11 @@
611
621
  value: function setError(error) {
612
622
  this.rawError = error;
613
623
  }
624
+ }, {
625
+ key: "validatedAtLeastOnce",
626
+ get: function get() {
627
+ return this._validatedOnce;
628
+ }
614
629
  }, {
615
630
  key: "waitForBlur",
616
631
  get: function get() {
@@ -740,6 +755,7 @@
740
755
 
741
756
  this._disabled = void 0;
742
757
  this._required = void 0;
758
+ this._validatedOnce = false;
743
759
  this._validating = false;
744
760
  this._initialValue = void 0;
745
761
  this._value = void 0;
@@ -772,6 +788,9 @@
772
788
  };
773
789
 
774
790
  mobx.makeObservable(this, {
791
+ resetValidatedOnce: mobx.action,
792
+ _validatedOnce: mobx.observable,
793
+ validatedAtLeastOnce: mobx.computed,
775
794
  _disabled: mobx.observable,
776
795
  _required: mobx.observable,
777
796
  waitForBlur: mobx.computed,
@@ -944,6 +963,16 @@
944
963
  * return the data as plain Javascript object (mobx magic removed from the fields)
945
964
  * */
946
965
 
966
+ }, {
967
+ key: "validatedAtLeastOnce",
968
+ get: function get() {
969
+ var _this3 = this;
970
+
971
+ var keys = Object.keys(this.fields);
972
+ return keys.every(function (key) {
973
+ return _this3.fields[key].validatedAtLeastOnce;
974
+ });
975
+ }
947
976
  }, {
948
977
  key: "dataIsReady",
949
978
  get: function get() {
@@ -952,21 +981,21 @@
952
981
  }, {
953
982
  key: "requiredFields",
954
983
  get: function get() {
955
- var _this3 = this;
984
+ var _this4 = this;
956
985
 
957
986
  var keys = Object.keys(this.fields);
958
987
  return keys.filter(function (key) {
959
- return _this3.fields[key].required;
988
+ return _this4.fields[key].required;
960
989
  });
961
990
  }
962
991
  }, {
963
992
  key: "requiredAreFilled",
964
993
  get: function get() {
965
- var _this4 = this;
994
+ var _this5 = this;
966
995
 
967
996
  var keys = Object.keys(this.fields);
968
997
  return keys.every(function (key) {
969
- var field = _this4.fields[key];
998
+ var field = _this5.fields[key];
970
999
 
971
1000
  if (field.required) {
972
1001
  return !!field.hasValue;
@@ -981,7 +1010,7 @@
981
1010
  // since some of the validators might be async validators
982
1011
  // this value might be false until the validation process finish
983
1012
  get: function get() {
984
- var _this5 = this;
1013
+ var _this6 = this;
985
1014
 
986
1015
  if (this._validating) {
987
1016
  return false; // consider the form invalid until the validation process finish
@@ -989,7 +1018,7 @@
989
1018
 
990
1019
  var keys = Object.keys(this.fields);
991
1020
  return keys.every(function (key) {
992
- var field = _this5.fields[key];
1021
+ var field = _this6.fields[key];
993
1022
  return !!field.valid;
994
1023
  });
995
1024
  }
@@ -1002,22 +1031,22 @@
1002
1031
  }, {
1003
1032
  key: "interacted",
1004
1033
  get: function get() {
1005
- var _this6 = this;
1034
+ var _this7 = this;
1006
1035
 
1007
1036
  var keys = this._fieldKeys();
1008
1037
 
1009
1038
  return keys.some(function (key) {
1010
- var field = _this6.fields[key];
1039
+ var field = _this7.fields[key];
1011
1040
  return !!field.interacted;
1012
1041
  });
1013
1042
  }
1014
1043
  }, {
1015
1044
  key: "summary",
1016
1045
  get: function get() {
1017
- var _this7 = this;
1046
+ var _this8 = this;
1018
1047
 
1019
1048
  return this._fieldKeys().reduce(function (seq, key) {
1020
- var field = _this7.fields[key];
1049
+ var field = _this8.fields[key];
1021
1050
 
1022
1051
  if (field.errorMessage) {
1023
1052
  seq.push(field.errorMessage);
@@ -1029,10 +1058,10 @@
1029
1058
  }, {
1030
1059
  key: "validating",
1031
1060
  get: function get() {
1032
- var _this8 = this;
1061
+ var _this9 = this;
1033
1062
 
1034
1063
  return this._validating || this._fieldKeys().some(function (key) {
1035
- var f = _this8._getField(key);
1064
+ var f = _this9._getField(key);
1036
1065
 
1037
1066
  return f.validating;
1038
1067
  });
@@ -1040,11 +1069,11 @@
1040
1069
  }, {
1041
1070
  key: "serializedData",
1042
1071
  get: function get() {
1043
- var _this9 = this;
1072
+ var _this10 = this;
1044
1073
 
1045
1074
  var keys = Object.keys(this.fields);
1046
1075
  return mobx.toJS(keys.reduce(function (seq, key) {
1047
- var field = _this9.fields[key];
1076
+ var field = _this10.fields[key];
1048
1077
  var value = mobx.toJS(field.value); // this is required to make sure forms that use the serializedData object
1049
1078
  // have the values without leading or trailing spaces
1050
1079
 
@@ -1065,7 +1094,7 @@
1065
1094
  }]);
1066
1095
 
1067
1096
  function FormModel() {
1068
- var _this10 = this;
1097
+ var _this11 = this;
1069
1098
 
1070
1099
  var _ref2 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
1071
1100
  _ref2$descriptors = _ref2.descriptors,
@@ -1080,7 +1109,7 @@
1080
1109
  this._validating = false;
1081
1110
 
1082
1111
  this.setValidating = function (validating) {
1083
- _this10._validating = validating;
1112
+ _this11._validating = validating;
1084
1113
  };
1085
1114
 
1086
1115
  this.addFields = function (fieldsDescriptor) {
@@ -1094,7 +1123,7 @@
1094
1123
  name = field.name,
1095
1124
  descriptor = _objectWithoutProperties(field, ["value", "name"]);
1096
1125
 
1097
- _this10._createField({
1126
+ _this11._createField({
1098
1127
  value: value,
1099
1128
  name: name,
1100
1129
  descriptor: descriptor
@@ -1109,7 +1138,7 @@
1109
1138
  value = _fieldsDescriptor$key.value,
1110
1139
  descriptor = _objectWithoutProperties(_fieldsDescriptor$key, ["value"]);
1111
1140
 
1112
- _this10._createField({
1141
+ _this11._createField({
1113
1142
  value: value,
1114
1143
  name: key,
1115
1144
  descriptor: descriptor
@@ -1118,6 +1147,8 @@
1118
1147
  };
1119
1148
 
1120
1149
  mobx.makeObservable(this, {
1150
+ resetValidatedOnce: mobx.action,
1151
+ validatedAtLeastOnce: mobx.computed,
1121
1152
  dataIsReady: mobx.computed,
1122
1153
  requiredFields: mobx.computed,
1123
1154
  requiredAreFilled: mobx.computed,
@@ -1162,10 +1193,10 @@
1162
1193
  }, {
1163
1194
  key: "_eachField",
1164
1195
  value: function _eachField(cb) {
1165
- var _this11 = this;
1196
+ var _this12 = this;
1166
1197
 
1167
1198
  Object.keys(this.fields).forEach(function (key) {
1168
- return cb(_this11.fields[key]);
1199
+ return cb(_this12.fields[key]);
1169
1200
  });
1170
1201
  }
1171
1202
  }, {
@@ -1183,11 +1214,11 @@
1183
1214
  }, {
1184
1215
  key: "disableFields",
1185
1216
  value: function disableFields(fieldKeys) {
1186
- var _this12 = this;
1217
+ var _this13 = this;
1187
1218
 
1188
1219
  if (!Array.isArray(fieldKeys)) throw new TypeError('fieldKeys should be an array with the names of the fields to disable');
1189
1220
  fieldKeys.forEach(function (key) {
1190
- var field = _this12._getField(key);
1221
+ var field = _this13._getField(key);
1191
1222
 
1192
1223
  field.setDisabled(true);
1193
1224
  });
@@ -1203,15 +1234,24 @@
1203
1234
  }, {
1204
1235
  key: "enableFields",
1205
1236
  value: function enableFields(fieldKeys) {
1206
- var _this13 = this;
1237
+ var _this14 = this;
1207
1238
 
1208
1239
  if (!Array.isArray(fieldKeys)) throw new TypeError('fieldKeys should be an array with the names of the fields to disable');
1209
1240
  fieldKeys.forEach(function (key) {
1210
- var field = _this13._getField(key);
1241
+ var field = _this14._getField(key);
1211
1242
 
1212
1243
  field.setDisabled(false);
1213
1244
  });
1214
1245
  }
1246
+ }, {
1247
+ key: "resetValidatedOnce",
1248
+ value: function resetValidatedOnce() {
1249
+ var _this15 = this;
1250
+
1251
+ this._fieldKeys().forEach(function (key) {
1252
+ _this15.fields[key].resetValidatedOnce();
1253
+ });
1254
+ }
1215
1255
  }]);
1216
1256
 
1217
1257
  return FormModel;
package/mobx-form.d.ts CHANGED
@@ -1,20 +1,20 @@
1
1
  declare module 'mobx-form' {
2
2
  export interface IValidatorFn<FieldType, ModelType> {
3
- (field: IField<FieldType>, fields: { [P in keyof ModelType]: IField<ModelType[P]> }, formModel: IFormModel<ModelType>): Promise<void>;
3
+ (field: IField<FieldType, ModelType>, fields: { [P in keyof ModelType]: IField<ModelType[P], ModelType> }, formModel: IFormModel<ModelType>): Promise<void>;
4
4
  }
5
5
 
6
6
  export interface IHasValueFn<T> {
7
7
  (value: T): boolean;
8
8
  }
9
9
 
10
- export interface IValidatorDescriptor<T> {
10
+ export interface IValidatorDescriptor<T, K> {
11
11
  waitForBlur?: boolean;
12
12
 
13
13
  disabled?: boolean;
14
14
 
15
15
  errorMessage?: string;
16
16
 
17
- validator?: IValidatorFn<T> | IValidatorFn<T>[];
17
+ validator?: IValidatorFn<T, K> | IValidatorFn<T, K>[];
18
18
 
19
19
  hasValue?: IHasValueFn<T>;
20
20
 
@@ -61,9 +61,12 @@ declare module 'mobx-form' {
61
61
  (options?: DisabledType): void;
62
62
  }
63
63
 
64
- export type ErrorLike = Error | { message?: string } | any;
65
-
66
- export interface IField<T> {
64
+ export interface IField<T, K> {
65
+
66
+ validatedAtLeastOnce: boolean;
67
+
68
+ resetValidatedOnce(): void;
69
+
67
70
  waitForBlur: boolean;
68
71
 
69
72
  disabled: boolean;
@@ -72,8 +75,6 @@ declare module 'mobx-form' {
72
75
 
73
76
  resetInteractedFlag(): void;
74
77
 
75
- markAsInteracted(): void;
76
-
77
78
  hasValue: boolean;
78
79
 
79
80
  blurred: boolean;
@@ -82,12 +83,6 @@ declare module 'mobx-form' {
82
83
 
83
84
  error?: string;
84
85
 
85
- rawError?: ErrorLike;
86
-
87
- setError(err: ErrorLike): void;
88
-
89
- resetError(): void;
90
-
91
86
  autoValidate: boolean;
92
87
 
93
88
  valid: boolean;
@@ -114,22 +109,26 @@ declare module 'mobx-form' {
114
109
 
115
110
  originalErrorMessage: string;
116
111
 
117
- setRequired(value: boolean | string): void;
112
+ setRequired(value: T): void;
118
113
 
119
114
  setErrorMessage(message: string): void;
120
115
 
121
- new (model: IFormModel<any>, value: T, validatorDescriptor: IValidatorDescriptor<T>, fieldName: string): IField<T>;
116
+ new (model: IFormModel<K>, value: T, validatorDescriptor: IValidatorDescriptor<T, K>, fieldName: string): IField<T, K>;
122
117
  }
123
118
 
124
119
  export interface IFormModel<T> {
120
+ validatedAtLeastOnce: boolean;
121
+
125
122
  dataIsReady: boolean;
126
123
 
127
124
  requiredFields: string[];
128
125
 
129
126
  requiredAreFilled: boolean;
127
+
128
+ resetValidatedOnce(): void;
130
129
 
131
130
  fields: {
132
- [P in keyof T]: IField<T[P]>;
131
+ [P in keyof T]: IField<T[P], T>;
133
132
  };
134
133
 
135
134
  valid: boolean;
@@ -166,7 +165,7 @@ declare module 'mobx-form' {
166
165
  }
167
166
 
168
167
  export type Descriptors<T> = IValidatorDescriptor<T[keyof T]>[] | {
169
- [P in keyof T]: IValidatorDescriptor<T[P]>;
168
+ [P in keyof T]: IValidatorDescriptor<T[P], T>;
170
169
  };
171
170
 
172
171
  export interface ICreateModelOptions<T> {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mobx-form",
3
- "version": "13.2.0",
3
+ "version": "13.3.0",
4
4
  "description": "A simple form helper for mobx",
5
5
  "main": "dist/mobx-form.cjs.js",
6
6
  "_browser": "dist/mobx-form.umd.js",
package/changelog.md DELETED
@@ -1,292 +0,0 @@
1
-
2
- # mobx-form - Changelog
3
- ## v13.2.0
4
- - **Other changes**
5
- - add option to store raw error - [e516ca0]( https://github.com/royriojas/mobx-form/commit/e516ca0 ), [Roy Riojas](https://github.com/Roy Riojas), 26/09/2021 07:49:51
6
-
7
-
8
- ## v13.1.1
9
- - **Bug Fixes**
10
- - fix typings - [973031f]( https://github.com/royriojas/mobx-form/commit/973031f ), [Roy Riojas](https://github.com/Roy Riojas), 14/09/2021 18:38:35
11
-
12
-
13
- ## v13.1.0
14
- - **Bug Fixes**
15
- - add method to mark as interacted - [0b56ae4]( https://github.com/royriojas/mobx-form/commit/0b56ae4 ), [Roy Riojas](https://github.com/Roy Riojas), 14/09/2021 18:35:37
16
-
17
-
18
- ## v13.0.0
19
- - **Bug Fixes**
20
- - include runtime to fix federated issue - [6a6d243]( https://github.com/royriojas/mobx-form/commit/6a6d243 ), [Roy Riojas](https://github.com/Roy Riojas), 13/09/2021 03:13:33
21
-
22
-
23
- ## v12.0.4
24
- - **Bug Fixes**
25
- - update types for updateFrom method - [8187fbc]( https://github.com/royriojas/mobx-form/commit/8187fbc ), [Roy Riojas](https://github.com/Roy Riojas), 29/08/2021 02:04:19
26
-
27
-
28
- ## v12.0.3
29
- - **Features**
30
- - add option to clear the error on value change - [bf370dc]( https://github.com/royriojas/mobx-form/commit/bf370dc ), [Roy Riojas](https://github.com/Roy Riojas), 08/06/2021 01:22:11
31
-
32
-
33
- ## v12.0.2
34
- - **Features**
35
- - Add custom debounce threshold for validator and ignoring of stale validations - [387d4b0]( https://github.com/royriojas/mobx-form/commit/387d4b0 ), [Roy Riojas](https://github.com/Roy Riojas), 08/06/2021 01:10:16
36
-
37
-
38
- ## v12.0.1
39
- - **Features**
40
- - Add better types for validator functions - [9170451]( https://github.com/royriojas/mobx-form/commit/9170451 ), [Roy Riojas](https://github.com/Roy Riojas), 04/06/2021 18:07:55
41
-
42
-
43
- ## v12.0.0
44
- - **Features**
45
- - Add isValidating prop to fields - [6240db6]( https://github.com/royriojas/mobx-form/commit/6240db6 ), [Roy Riojas](https://github.com/Roy Riojas), 26/03/2021 05:21:23
46
-
47
-
48
- ## v11.0.1
49
- - **Refactoring**
50
- - use types instead of typings - [d53d463]( https://github.com/royriojas/mobx-form/commit/d53d463 ), [Roy Riojas](https://github.com/Roy Riojas), 07/02/2021 01:52:43
51
-
52
-
53
- ## v11.0.0
54
- - **Bug Fixes**
55
- - fields with boolean values should be considered empty only if no value is set - [98112c6]( https://github.com/royriojas/mobx-form/commit/98112c6 ), [Roy Riojas](https://github.com/Roy Riojas), 21/01/2021 03:58:25
56
-
57
-
58
- ## v10.1.2
59
- - **Bug Fixes**
60
- - fix TS types - [6c9c250]( https://github.com/royriojas/mobx-form/commit/6c9c250 ), [Roy Riojas](https://github.com/Roy Riojas), 13/01/2021 21:42:54
61
-
62
-
63
- ## v10.1.1
64
- - **Refactoring**
65
- - upgrade deps to latest versions - [d4d2256]( https://github.com/royriojas/mobx-form/commit/d4d2256 ), [Roy Riojas](https://github.com/Roy Riojas), 13/01/2021 18:49:59
66
-
67
-
68
- ## v10.1.0
69
- - **Refactoring**
70
- - add option to not to throw if field is missing - [b51a63c]( https://github.com/royriojas/mobx-form/commit/b51a63c ), [Roy Riojas](https://github.com/Roy Riojas), 13/01/2021 18:28:20
71
-
72
-
73
- ## v10.0.5
74
- - **Refactoring**
75
- - Upgrade typescript types - [e37000c]( https://github.com/royriojas/mobx-form/commit/e37000c ), [Roy Riojas](https://github.com/Roy Riojas), 16/10/2020 01:58:23
76
-
77
-
78
- ## v10.0.4
79
- - **Refactoring**
80
- - Upgrade typescript types - [64610cf]( https://github.com/royriojas/mobx-form/commit/64610cf ), [Roy Riojas](https://github.com/Roy Riojas), 16/10/2020 01:52:30
81
-
82
-
83
- ## v10.0.3
84
- - **Refactoring**
85
- - Upgrade typescript types - [6edfe0f]( https://github.com/royriojas/mobx-form/commit/6edfe0f ), [Roy Riojas](https://github.com/Roy Riojas), 16/10/2020 00:50:18
86
-
87
-
88
- ## v10.0.2
89
- - **Refactoring**
90
- - Upgrade typescript types - [be233df]( https://github.com/royriojas/mobx-form/commit/be233df ), [Roy Riojas](https://github.com/Roy Riojas), 16/10/2020 00:47:04
91
-
92
-
93
- ## v10.0.1
94
- - **Refactoring**
95
- - Upgrade babel runtime dep - [0f6dc9c]( https://github.com/royriojas/mobx-form/commit/0f6dc9c ), [Roy Riojas](https://github.com/Roy Riojas), 15/10/2020 23:23:40
96
-
97
-
98
- ## v10.0.0
99
- - **Bug Fixes**
100
- - fix lint issues - [0bc9c13]( https://github.com/royriojas/mobx-form/commit/0bc9c13 ), [Roy Riojas](https://github.com/Roy Riojas), 15/10/2020 23:19:25
101
-
102
-
103
- - **Refactoring**
104
- - Migrate to Mobx@6 - [0c6a711]( https://github.com/royriojas/mobx-form/commit/0c6a711 ), [Roy Riojas](https://github.com/Roy Riojas), 15/10/2020 23:17:17
105
-
106
-
107
- ## v9.0.7
108
- - **Refactoring**
109
- - Add license file to mobx-form - [e25d4b3]( https://github.com/royriojas/mobx-form/commit/e25d4b3 ), [Roy Riojas](https://github.com/Roy Riojas), 04/09/2020 12:52:16
110
-
111
-
112
- ## v9.0.6
113
- - **Refactoring**
114
- - force validation marks the field as blurred - [e520d0c]( https://github.com/royriojas/mobx-form/commit/e520d0c ), [Roy Riojas](https://github.com/Roy Riojas), 14/05/2020 21:59:39
115
-
116
-
117
- ## v9.0.5
118
- - **Refactoring**
119
- - Update tests and typings - [5df9baa]( https://github.com/royriojas/mobx-form/commit/5df9baa ), [Roy Riojas](https://github.com/Roy Riojas), 14/05/2020 21:46:02
120
-
121
-
122
- ## v9.0.4
123
- - **Refactoring**
124
- - Update typings - [994336d]( https://github.com/royriojas/mobx-form/commit/994336d ), [Roy Riojas](https://github.com/Roy Riojas), 14/05/2020 20:16:51
125
-
126
-
127
- ## v9.0.3
128
- - **Refactoring**
129
- - Make the required prop also a string - [8b6995e]( https://github.com/royriojas/mobx-form/commit/8b6995e ), [Roy Riojas](https://github.com/Roy Riojas), 14/05/2020 20:03:02
130
-
131
-
132
- ## v9.0.1-beta.1
133
- - **Refactoring**
134
- - Add typings for mobx-form - [bceb65f]( https://github.com/royriojas/mobx-form/commit/bceb65f ), [Roy Riojas](https://github.com/Roy Riojas), 14/05/2020 19:46:10
135
-
136
-
137
- ## v9.0.0
138
- - **Refactoring**
139
- - Add a minor version change - [e6a016c]( https://github.com/royriojas/mobx-form/commit/e6a016c ), [Roy Riojas](https://github.com/Roy Riojas), 14/05/2020 01:06:33
140
-
141
-
142
- ## v8.0.0-beta.4
143
- - **Refactoring**
144
- - Upgrade beta version - [f467f2e]( https://github.com/royriojas/mobx-form/commit/f467f2e ), [Roy Riojas](https://github.com/Roy Riojas), 13/05/2020 23:27:03
145
-
146
-
147
- - publish beta-2 version - [9eb8f21]( https://github.com/royriojas/mobx-form/commit/9eb8f21 ), [Roy Riojas](https://github.com/Roy Riojas), 13/05/2020 23:16:39
148
-
149
-
150
- - bump beta version - [4ad0319]( https://github.com/royriojas/mobx-form/commit/4ad0319 ), [Roy Riojas](https://github.com/Roy Riojas), 13/05/2020 23:05:12
151
-
152
-
153
- - Upgrade modules - [b88b0d0]( https://github.com/royriojas/mobx-form/commit/b88b0d0 ), [Roy Riojas](https://github.com/Roy Riojas), 13/05/2020 23:03:38
154
-
155
-
156
- - Add blurredOnce getter - [b9b1309]( https://github.com/royriojas/mobx-form/commit/b9b1309 ), [Roy Riojas](https://github.com/Roy Riojas), 13/05/2020 21:25:42
157
-
158
-
159
- - Update babel pacakge version - [6a85d4d]( https://github.com/royriojas/mobx-form/commit/6a85d4d ), [Roy Riojas](https://github.com/Roy Riojas), 28/04/2020 01:34:54
160
-
161
-
162
- - Make use of latest rollup and babel plugins - [6bb8cbd]( https://github.com/royriojas/mobx-form/commit/6bb8cbd ), [Roy Riojas](https://github.com/Roy Riojas), 28/04/2020 01:34:22
163
-
164
-
165
- ## v8.0.0
166
- - **Refactoring**
167
- - Fix lint - [11eb2d6]( https://github.com/royriojas/mobx-form/commit/11eb2d6 ), [royriojas](https://github.com/royriojas), 10/09/2019 09:19:36
168
-
169
-
170
- - Major refactor on mobx-form and adding tests - [d9b0da0]( https://github.com/royriojas/mobx-form/commit/d9b0da0 ), [royriojas](https://github.com/royriojas), 10/09/2019 09:18:28
171
-
172
-
173
- ## v7.0.1
174
- - **Refactoring**
175
- - remove Observable arrays from serialization of fields - [741487e]( https://github.com/royriojas/mobx-form/commit/741487e ), [royriojas](https://github.com/royriojas), 19/08/2019 18:13:49
176
-
177
-
178
- ## v7.0.0-alpha.3
179
- - **Refactoring**
180
- - Attempt to change browser field to something webpack likes - take 2 - [95783ad]( https://github.com/royriojas/mobx-form/commit/95783ad ), [royriojas](https://github.com/royriojas), 04/08/2019 22:54:02
181
-
182
-
183
- ## v7.0.0-alpha.2
184
- - **Refactoring**
185
- - Attempt to change browser field to something webpack likes - [a7d9d65]( https://github.com/royriojas/mobx-form/commit/a7d9d65 ), [royriojas](https://github.com/royriojas), 04/08/2019 22:50:34
186
-
187
-
188
- ## v7.0.0-alpha.1
189
- - **Bug Fixes**
190
- - Fix lint issues - [b0a850d]( https://github.com/royriojas/mobx-form/commit/b0a850d ), [royriojas](https://github.com/royriojas), 04/08/2019 22:13:30
191
-
192
-
193
- ## v7.0.0-alpha.0
194
- - **Refactoring**
195
- - Simplify and improve mobx-form api - [8f48e28]( https://github.com/royriojas/mobx-form/commit/8f48e28 ), [royriojas](https://github.com/royriojas), 04/08/2019 22:10:29
196
-
197
-
198
- ## v5.2.2
199
- - **Refactoring**
200
- - Upgrade node_modules and use latest babel - [b795e13]( https://github.com/royriojas/mobx-form/commit/b795e13 ), [Roy Riojas](https://github.com/Roy Riojas), 07/05/2019 22:11:58
201
-
202
- Breaking change as now we transpile 2 versions of the module one for evergreen browsers and one for IE11
203
-
204
- ## v5.2.1
205
- - **Refactoring**
206
- - Add rest spread support - [48ae905]( https://github.com/royriojas/mobx-form/commit/48ae905 ), [Roy Riojas](https://github.com/Roy Riojas), 13/01/2019 18:58:53
207
-
208
-
209
- ## v5.2.0
210
- - **Features**
211
- - Add support to create a form from an array or an object descriptor - [19072dc]( https://github.com/royriojas/mobx-form/commit/19072dc ), [Roy Riojas](https://github.com/Roy Riojas), 13/01/2019 17:51:12
212
-
213
-
214
- ## v5.0.3
215
- - **Features**
216
- - pass the model instance to the validators - [f4045c1]( https://github.com/royriojas/mobx-form/commit/f4045c1 ), [Roy Riojas](https://github.com/Roy Riojas), 20/12/2018 01:50:08
217
-
218
-
219
- ## v5.0.2
220
- - **Refactoring**
221
- - Be compatible with enforceActions option of mobx - [d419fba]( https://github.com/royriojas/mobx-form/commit/d419fba ), [Roy Riojas](https://github.com/Roy Riojas), 17/08/2018 04:10:08
222
-
223
-
224
- ## v5.0.1
225
- - **Bug Fixes**
226
- - wrong entry point for UMD target - [de06c9d]( https://github.com/royriojas/mobx-form/commit/de06c9d ), [Roy Riojas](https://github.com/Roy Riojas), 09/08/2018 20:28:53
227
-
228
-
229
- ## v5.0.0
230
- - **Refactoring**
231
- - remove dependency on regenerator - [e8bdbc9]( https://github.com/royriojas/mobx-form/commit/e8bdbc9 ), [Roy Riojas](https://github.com/Roy Riojas), 09/08/2018 20:27:41
232
-
233
-
234
- ## v4.0.0
235
- - **Refactoring**
236
- - Create a smaller umd bundle - [81d81e3]( https://github.com/royriojas/mobx-form/commit/81d81e3 ), [Roy Riojas](https://github.com/Roy Riojas), 09/08/2018 20:07:12
237
-
238
-
239
- - **Other changes**
240
- - Update FormModel.test.js - [bff561e]( https://github.com/royriojas/mobx-form/commit/bff561e ), [Roy Riojas](https://github.com/Roy Riojas), 09/08/2018 19:24:08
241
-
242
-
243
- ## v3.0.2
244
- - **Refactoring**
245
- - Add prepublish script - [f0dde93]( https://github.com/royriojas/mobx-form/commit/f0dde93 ), [Roy Riojas](https://github.com/Roy Riojas), 08/08/2018 19:32:01
246
-
247
-
248
- ## v3.0.1
249
- - **Refactoring**
250
- - rename the bundle output - [49d010d]( https://github.com/royriojas/mobx-form/commit/49d010d ), [Roy Riojas](https://github.com/Roy Riojas), 08/08/2018 19:24:28
251
-
252
-
253
- ## v3.0.0
254
- - **Refactoring**
255
- - Use rollup to create umd/esm/cjs bundles - [697d75c]( https://github.com/royriojas/mobx-form/commit/697d75c ), [Roy Riojas](https://github.com/Roy Riojas), 08/08/2018 12:38:47
256
-
257
-
258
- ## v2.1.1
259
- - **Documentation**
260
- - Fix missing peer dependency - [9feae5e]( https://github.com/royriojas/mobx-form/commit/9feae5e ), [Roy Riojas](https://github.com/Roy Riojas), 08/08/2018 10:57:06
261
-
262
-
263
- ## v2.1.0
264
- - **Documentation**
265
- - update documenation - [7718d79]( https://github.com/royriojas/mobx-form/commit/7718d79 ), [Roy Riojas](https://github.com/Roy Riojas), 08/08/2018 10:16:28
266
-
267
-
268
- ## v2.0.0
269
- - **Refactoring**
270
- - Update FormModel to add new features and tests - [4e449d9]( https://github.com/royriojas/mobx-form/commit/4e449d9 ), [Roy Riojas](https://github.com/Roy Riojas), 08/08/2018 08:28:41
271
-
272
-
273
- ## v1.0.1
274
- - **Build Scripts Changes**
275
- - Add build tasks - [2b36cf5]( https://github.com/royriojas/mobx-form/commit/2b36cf5 ), [Roy Riojas](https://github.com/Roy Riojas), 23/06/2016 18:26:51
276
-
277
-
278
- - **Refactoring**
279
- - Add a helper to improve how fields are set - [c208bc7]( https://github.com/royriojas/mobx-form/commit/c208bc7 ), [Roy Riojas](https://github.com/Roy Riojas), 23/06/2016 18:22:35
280
-
281
-
282
- - **Documentation**
283
- - add more documentation - [443d90d]( https://github.com/royriojas/mobx-form/commit/443d90d ), [Roy Riojas](https://github.com/Roy Riojas), 15/06/2016 11:02:55
284
-
285
-
286
- - add missed import - [3da648e]( https://github.com/royriojas/mobx-form/commit/3da648e ), [Roy Riojas](https://github.com/Roy Riojas), 15/06/2016 10:53:32
287
-
288
-
289
- - **Features**
290
- - initial version - [02003a4]( https://github.com/royriojas/mobx-form/commit/02003a4 ), [Roy Riojas](https://github.com/Roy Riojas), 15/06/2016 10:49:00
291
-
292
-