redux-freeform 5.3.0 → 5.4.0-beta.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/redux-freeform.cjs.js +472 -373
- package/dist/redux-freeform.esm.js +472 -373
- package/dist/redux-freeform.umd.js +459 -375
- package/package.json +5 -4
|
@@ -2,10 +2,68 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
require('core-js/modules/es.regexp.exec.js');
|
|
6
|
+
require('core-js/modules/es.number.constructor.js');
|
|
7
|
+
require('core-js/modules/es.array.reduce.js');
|
|
8
|
+
require('core-js/modules/es.object.to-string.js');
|
|
9
|
+
require('core-js/modules/es.parse-int.js');
|
|
10
|
+
require('core-js/modules/es.array.slice.js');
|
|
11
|
+
require('core-js/modules/es.regexp.constructor.js');
|
|
12
|
+
require('core-js/modules/es.regexp.to-string.js');
|
|
13
|
+
require('core-js/modules/es.array.map.js');
|
|
14
|
+
require('core-js/modules/es.string.split.js');
|
|
15
|
+
require('core-js/modules/es.array.filter.js');
|
|
16
|
+
require('core-js/modules/es.array.concat.js');
|
|
17
|
+
require('core-js/modules/es.object.keys.js');
|
|
18
|
+
require('core-js/modules/es.object.entries.js');
|
|
19
|
+
|
|
20
|
+
function _unsupportedIterableToArray(o, minLen) {
|
|
21
|
+
if (!o) return;
|
|
22
|
+
if (typeof o === "string") return _arrayLikeToArray(o, minLen);
|
|
23
|
+
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
24
|
+
if (n === "Object" && o.constructor) n = o.constructor.name;
|
|
25
|
+
if (n === "Map" || n === "Set") return Array.from(o);
|
|
26
|
+
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function _arrayLikeToArray(arr, len) {
|
|
30
|
+
if (len == null || len > arr.length) len = arr.length;
|
|
31
|
+
|
|
32
|
+
for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
|
|
33
|
+
|
|
34
|
+
return arr2;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function _createForOfIteratorHelperLoose(o, allowArrayLike) {
|
|
38
|
+
var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"];
|
|
39
|
+
if (it) return (it = it.call(o)).next.bind(it);
|
|
40
|
+
|
|
41
|
+
if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") {
|
|
42
|
+
if (it) o = it;
|
|
43
|
+
var i = 0;
|
|
44
|
+
return function () {
|
|
45
|
+
if (i >= o.length) return {
|
|
46
|
+
done: true
|
|
47
|
+
};
|
|
48
|
+
return {
|
|
49
|
+
done: false,
|
|
50
|
+
value: o[i++]
|
|
51
|
+
};
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
var validatorToPredicate = function validatorToPredicate(validatorFn, emptyCase) {
|
|
59
|
+
return function (value) {
|
|
60
|
+
for (var _len = arguments.length, rest = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
61
|
+
rest[_key - 1] = arguments[_key];
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
return value === "" ? emptyCase : validatorFn.apply(void 0, [value].concat(rest));
|
|
65
|
+
};
|
|
66
|
+
};
|
|
9
67
|
|
|
10
68
|
var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
|
|
11
69
|
|
|
@@ -41,10 +99,19 @@ var isSameOrAfter$1 = {exports: {}};
|
|
|
41
99
|
|
|
42
100
|
var isSameOrAfter = isSameOrAfter$1.exports;
|
|
43
101
|
|
|
44
|
-
|
|
102
|
+
var createValidator = function createValidator(type, error) {
|
|
103
|
+
var validator = function validator() {
|
|
104
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
105
|
+
args[_key] = arguments[_key];
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
return {
|
|
109
|
+
type: type,
|
|
110
|
+
args: args,
|
|
111
|
+
error: error
|
|
112
|
+
};
|
|
113
|
+
};
|
|
45
114
|
|
|
46
|
-
const createValidator = (type, error) => {
|
|
47
|
-
let validator = (...args) => ({ type, args, error });
|
|
48
115
|
validator.error = error;
|
|
49
116
|
return validator;
|
|
50
117
|
};
|
|
@@ -52,428 +119,408 @@ const createValidator = (type, error) => {
|
|
|
52
119
|
dayjs.extend(customParseFormat);
|
|
53
120
|
dayjs.extend(isSameOrBefore);
|
|
54
121
|
dayjs.extend(isSameOrAfter);
|
|
122
|
+
var validatorFns = {};
|
|
123
|
+
var REQUIRED = "validator/REQUIRED";
|
|
124
|
+
var REQUIRED_ERROR = "error/REQUIRED";
|
|
125
|
+
var required = createValidator(REQUIRED, REQUIRED_ERROR);
|
|
126
|
+
|
|
127
|
+
validatorFns[REQUIRED] = function (value, args, form) {
|
|
128
|
+
return value !== "";
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
var ONLY_INTEGERS = "validator/ONLY_INTEGERS";
|
|
132
|
+
var ONLY_INTEGERS_ERROR = "error/ONLY_INTEGERS";
|
|
133
|
+
var onlyIntegers = createValidator(ONLY_INTEGERS, ONLY_INTEGERS_ERROR);
|
|
134
|
+
|
|
135
|
+
validatorFns[ONLY_INTEGERS] = function (value, args, form) {
|
|
136
|
+
return /^(-?\d+)?$/.test(value);
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
var ONLY_NATURALS = "validator/ONLY_NATURALS";
|
|
140
|
+
var ONLY_NATURALS_ERROR = "error/ONLY_NATURALS";
|
|
141
|
+
var onlyNaturals = createValidator(ONLY_NATURALS, ONLY_NATURALS_ERROR);
|
|
142
|
+
|
|
143
|
+
validatorFns[ONLY_NATURALS] = function (value, args, form) {
|
|
144
|
+
return /^(\d+)?$/.test(value);
|
|
145
|
+
};
|
|
55
146
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
validatorFns[REQUIRED] = (value, args, form) => value !== "";
|
|
62
|
-
|
|
63
|
-
const ONLY_INTEGERS = "validator/ONLY_INTEGERS";
|
|
64
|
-
const ONLY_INTEGERS_ERROR = "error/ONLY_INTEGERS";
|
|
65
|
-
const onlyIntegers = createValidator(ONLY_INTEGERS, ONLY_INTEGERS_ERROR);
|
|
66
|
-
validatorFns[ONLY_INTEGERS] = (value, args, form) => /^(-?\d+)?$/.test(value);
|
|
67
|
-
|
|
68
|
-
const ONLY_NATURALS = "validator/ONLY_NATURALS";
|
|
69
|
-
const ONLY_NATURALS_ERROR = "error/ONLY_NATURALS";
|
|
70
|
-
const onlyNaturals = createValidator(ONLY_NATURALS, ONLY_NATURALS_ERROR);
|
|
71
|
-
validatorFns[ONLY_NATURALS] = (value, args, form) => /^(\d+)?$/.test(value);
|
|
72
|
-
|
|
73
|
-
const NUMBER_LESS_THAN = "validator/NUMBER_LESS_THAN";
|
|
74
|
-
const NUMBER_LESS_THAN_ERROR = "error/NUMBER_LESS_THAN";
|
|
75
|
-
const numberLessThan = createValidator(
|
|
76
|
-
NUMBER_LESS_THAN,
|
|
77
|
-
NUMBER_LESS_THAN_ERROR
|
|
78
|
-
);
|
|
79
|
-
validatorFns[NUMBER_LESS_THAN] = (value, args, form) => {
|
|
147
|
+
var NUMBER_LESS_THAN = "validator/NUMBER_LESS_THAN";
|
|
148
|
+
var NUMBER_LESS_THAN_ERROR = "error/NUMBER_LESS_THAN";
|
|
149
|
+
var numberLessThan = createValidator(NUMBER_LESS_THAN, NUMBER_LESS_THAN_ERROR);
|
|
150
|
+
|
|
151
|
+
validatorFns[NUMBER_LESS_THAN] = function (value, args, form) {
|
|
80
152
|
if (value === "") {
|
|
81
153
|
return true;
|
|
82
154
|
}
|
|
155
|
+
|
|
83
156
|
return Number(value) < args[0];
|
|
84
157
|
};
|
|
85
158
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
NUMBER_LESS_THAN_OR_EQUAL_TO,
|
|
92
|
-
NUMBER_LESS_THAN_OR_EQUAL_TO_ERROR
|
|
93
|
-
);
|
|
94
|
-
validatorFns[NUMBER_LESS_THAN_OR_EQUAL_TO] = (value, args, form) => {
|
|
159
|
+
var NUMBER_LESS_THAN_OR_EQUAL_TO = "validator/NUMBER_LESS_THAN_OR_EQUAL_TO";
|
|
160
|
+
var NUMBER_LESS_THAN_OR_EQUAL_TO_ERROR = "error/NUMBER_LESS_THAN_OR_EQUAL_TO";
|
|
161
|
+
var numberLessThanOrEqualTo = createValidator(NUMBER_LESS_THAN_OR_EQUAL_TO, NUMBER_LESS_THAN_OR_EQUAL_TO_ERROR);
|
|
162
|
+
|
|
163
|
+
validatorFns[NUMBER_LESS_THAN_OR_EQUAL_TO] = function (value, args, form) {
|
|
95
164
|
if (value === "") {
|
|
96
165
|
return true;
|
|
97
166
|
}
|
|
167
|
+
|
|
98
168
|
return Number(value) <= args[0];
|
|
99
169
|
};
|
|
100
170
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
);
|
|
107
|
-
validatorFns[NUMBER_GREATER_THAN] = (value, args, form) => {
|
|
171
|
+
var NUMBER_GREATER_THAN = "validator/NUMBER_GREATER_THAN";
|
|
172
|
+
var NUMBER_GREATER_THAN_ERROR = "error/NUMBER_GREATER_THAN";
|
|
173
|
+
var numberGreaterThan = createValidator(NUMBER_GREATER_THAN, NUMBER_GREATER_THAN_ERROR);
|
|
174
|
+
|
|
175
|
+
validatorFns[NUMBER_GREATER_THAN] = function (value, args, form) {
|
|
108
176
|
if (value === "") {
|
|
109
177
|
return true;
|
|
110
178
|
}
|
|
179
|
+
|
|
111
180
|
return Number(value) > args[0];
|
|
112
181
|
};
|
|
113
182
|
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
NUMBER_GREATER_THAN_OR_EQUAL_TO,
|
|
120
|
-
NUMBER_GREATER_THAN_OR_EQUAL_TO_ERROR
|
|
121
|
-
);
|
|
122
|
-
validatorFns[NUMBER_GREATER_THAN_OR_EQUAL_TO] = (value, args, form) => {
|
|
183
|
+
var NUMBER_GREATER_THAN_OR_EQUAL_TO = "validator/NUMBER_GREATER_THAN_OR_EQUAL_TO";
|
|
184
|
+
var NUMBER_GREATER_THAN_OR_EQUAL_TO_ERROR = "error/NUMBER_GREATER_THAN_OR_EQUAL_TO";
|
|
185
|
+
var numberGreaterThanOrEqualTo = createValidator(NUMBER_GREATER_THAN_OR_EQUAL_TO, NUMBER_GREATER_THAN_OR_EQUAL_TO_ERROR);
|
|
186
|
+
|
|
187
|
+
validatorFns[NUMBER_GREATER_THAN_OR_EQUAL_TO] = function (value, args, form) {
|
|
123
188
|
if (value === "") {
|
|
124
189
|
return true;
|
|
125
190
|
}
|
|
191
|
+
|
|
126
192
|
return Number(value) >= args[0];
|
|
127
193
|
};
|
|
128
194
|
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
195
|
+
var MATCHES_FIELD = "validator/MATCHES_FIELD";
|
|
196
|
+
var MATCHES_FIELD_ERROR = "error/MATCHES_FIELD";
|
|
197
|
+
var matchesField = createValidator(MATCHES_FIELD, MATCHES_FIELD_ERROR);
|
|
198
|
+
|
|
199
|
+
validatorFns[MATCHES_FIELD] = function (value, args, form) {
|
|
200
|
+
var _dependentField$rawVa;
|
|
201
|
+
|
|
202
|
+
var dependentField = form[args[0]];
|
|
203
|
+
var dependentFieldValue = (_dependentField$rawVa = dependentField == null ? void 0 : dependentField.rawValue) != null ? _dependentField$rawVa : "";
|
|
204
|
+
|
|
135
205
|
if (dependentField === undefined) {
|
|
136
|
-
throw new Error(
|
|
137
|
-
`${args[0]} was passed to matchesField, but that field does not exist in the form`
|
|
138
|
-
);
|
|
206
|
+
throw new Error(args[0] + " was passed to matchesField, but that field does not exist in the form");
|
|
139
207
|
}
|
|
208
|
+
|
|
140
209
|
return value === dependentFieldValue;
|
|
141
210
|
};
|
|
142
211
|
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
) => ({
|
|
158
|
-
type: VALIDATE_WHEN,
|
|
159
|
-
args: [dependentValidator, primaryValidator, optionalFieldName],
|
|
160
|
-
error: dependentValidator.error
|
|
161
|
-
});
|
|
212
|
+
var validateWhenErrorMessage = function validateWhenErrorMessage(type) {
|
|
213
|
+
return type + " was passed to validateWhen, but that validator type does not exist.\n Please check that you are only calling validator creator functions exported from\n redux-freeform in your form config and that you didn't forget to\n invoke the validator creator (you cannot pass the functions themselves to\n createFormState). Also make sure you aren't passing validateWhen() to validateWhen\n as the primary validator.";
|
|
214
|
+
};
|
|
215
|
+
var VALIDATE_WHEN = "validator/VALIDATE_WHEN";
|
|
216
|
+
var VALIDATE_WHEN_ERROR = "error/VALIDATE_WHEN";
|
|
217
|
+
|
|
218
|
+
var validateWhen = function validateWhen(dependentValidator, primaryValidator, optionalFieldName) {
|
|
219
|
+
return {
|
|
220
|
+
type: VALIDATE_WHEN,
|
|
221
|
+
args: [dependentValidator, primaryValidator, optionalFieldName],
|
|
222
|
+
error: dependentValidator.error
|
|
223
|
+
};
|
|
224
|
+
};
|
|
225
|
+
|
|
162
226
|
validateWhen.error = VALIDATE_WHEN_ERROR;
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
) {
|
|
227
|
+
|
|
228
|
+
validatorFns[VALIDATE_WHEN] = function (value, args, form) {
|
|
229
|
+
var dependentValidator = args[0],
|
|
230
|
+
primaryValidator = args[1],
|
|
231
|
+
optionalFieldName = args[2];
|
|
232
|
+
var dependsOnOtherField = typeof optionalFieldName === "string";
|
|
233
|
+
|
|
234
|
+
if (primaryValidator.type === undefined || typeof validatorFns[primaryValidator.type] !== "function") {
|
|
171
235
|
throw new Error(validateWhenErrorMessage(primaryValidator.type));
|
|
172
236
|
}
|
|
237
|
+
|
|
173
238
|
if (dependsOnOtherField && form[optionalFieldName] === undefined) {
|
|
174
|
-
throw new Error(
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
dependentValidator.args,
|
|
196
|
-
form
|
|
197
|
-
)
|
|
198
|
-
: true;
|
|
239
|
+
throw new Error(args[2] + " was passed to matchesField, but that field does not exist in the form");
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
var primaryPredicate = validatorToPredicate(validatorFns[primaryValidator.type], false);
|
|
243
|
+
var primaryValue = dependsOnOtherField ? form[optionalFieldName].rawValue : value;
|
|
244
|
+
var primaryPredicatePassed = primaryPredicate(primaryValue, primaryValidator.args, form);
|
|
245
|
+
return primaryPredicatePassed ? validatorFns[dependentValidator.type](value, dependentValidator.args, form) : true;
|
|
246
|
+
};
|
|
247
|
+
|
|
248
|
+
var validateSumErrorMessage = function validateSumErrorMessage(type) {
|
|
249
|
+
return type + " was passed to validateSum, but that validator type does not exist.\n Please check that you are only calling validator creator functions exported from\n redux-freeform in your form config and that you didn't forget to\n invoke the validator creator (you cannot pass the functions themselves to\n createFormState).";
|
|
250
|
+
};
|
|
251
|
+
var VALIDATE_SUM = "validator/VALIDATE_SUM";
|
|
252
|
+
var VALIDATE_SUM_ERROR = "error/VALIDATE_SUM";
|
|
253
|
+
|
|
254
|
+
var validateSum = function validateSum(validator, fieldNamesArray) {
|
|
255
|
+
return {
|
|
256
|
+
type: VALIDATE_SUM,
|
|
257
|
+
args: [validator, fieldNamesArray],
|
|
258
|
+
error: validator.error
|
|
259
|
+
};
|
|
199
260
|
};
|
|
200
261
|
|
|
201
|
-
const validateSumErrorMessage = type =>
|
|
202
|
-
`${type} was passed to validateSum, but that validator type does not exist.
|
|
203
|
-
Please check that you are only calling validator creator functions exported from
|
|
204
|
-
redux-freeform in your form config and that you didn't forget to
|
|
205
|
-
invoke the validator creator (you cannot pass the functions themselves to
|
|
206
|
-
createFormState).`;
|
|
207
|
-
const VALIDATE_SUM = "validator/VALIDATE_SUM";
|
|
208
|
-
const VALIDATE_SUM_ERROR = "error/VALIDATE_SUM";
|
|
209
|
-
const validateSum = (validator, fieldNamesArray) => ({
|
|
210
|
-
type: VALIDATE_SUM,
|
|
211
|
-
args: [validator, fieldNamesArray],
|
|
212
|
-
error: validator.error
|
|
213
|
-
});
|
|
214
262
|
validateSum.error = VALIDATE_SUM_ERROR;
|
|
215
|
-
validatorFns[VALIDATE_SUM] = (value, args, form) => {
|
|
216
|
-
const [validator, fieldNamesArray] = args;
|
|
217
263
|
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
264
|
+
validatorFns[VALIDATE_SUM] = function (value, args, form) {
|
|
265
|
+
var validator = args[0],
|
|
266
|
+
fieldNamesArray = args[1];
|
|
267
|
+
|
|
268
|
+
if (validator.type === undefined || typeof validatorFns[validator.type] !== "function") {
|
|
222
269
|
throw new Error(validateSumErrorMessage(validator.type));
|
|
223
270
|
}
|
|
224
271
|
|
|
225
|
-
for (
|
|
272
|
+
for (var _iterator = _createForOfIteratorHelperLoose(fieldNamesArray), _step; !(_step = _iterator()).done;) {
|
|
273
|
+
var fieldName = _step.value;
|
|
274
|
+
|
|
226
275
|
if (form[fieldName] === undefined) {
|
|
227
|
-
throw new Error(
|
|
228
|
-
`${fieldName} was passed to matchesField, but that field does not exist in the form`
|
|
229
|
-
);
|
|
276
|
+
throw new Error(fieldName + " was passed to matchesField, but that field does not exist in the form");
|
|
230
277
|
}
|
|
231
278
|
}
|
|
232
279
|
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
);
|
|
237
|
-
|
|
280
|
+
var sum = fieldNamesArray.reduce(function (acc, curr) {
|
|
281
|
+
return acc + Number(form[curr].rawValue);
|
|
282
|
+
}, Number(value));
|
|
238
283
|
return validatorFns[validator.type](sum, validator.args, form);
|
|
239
284
|
};
|
|
240
285
|
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
286
|
+
var HAS_LENGTH = "validator/HAS_LENGTH";
|
|
287
|
+
var HAS_LENGTH_ERROR = "error/HAS_LENGTH";
|
|
288
|
+
var hasLength = createValidator(HAS_LENGTH, HAS_LENGTH_ERROR);
|
|
289
|
+
|
|
290
|
+
validatorFns[HAS_LENGTH] = function (value, args, form) {
|
|
245
291
|
if (value === "") {
|
|
246
292
|
return true;
|
|
247
293
|
}
|
|
248
|
-
|
|
249
|
-
|
|
294
|
+
|
|
295
|
+
var min = args[0];
|
|
296
|
+
var max = args[1];
|
|
297
|
+
|
|
250
298
|
if (max == undefined || min == undefined) {
|
|
251
|
-
throw new Error(
|
|
252
|
-
"Max and min need to be defined for hasLength, both or one of them is undefined"
|
|
253
|
-
);
|
|
299
|
+
throw new Error("Max and min need to be defined for hasLength, both or one of them is undefined");
|
|
254
300
|
}
|
|
301
|
+
|
|
255
302
|
if (max < min) {
|
|
256
|
-
throw new Error(
|
|
257
|
-
"hasLength validator was passed a min greater than the max"
|
|
258
|
-
);
|
|
303
|
+
throw new Error("hasLength validator was passed a min greater than the max");
|
|
259
304
|
}
|
|
260
|
-
|
|
305
|
+
|
|
306
|
+
var valueLength = value.length;
|
|
261
307
|
return max >= valueLength && valueLength >= min;
|
|
262
308
|
};
|
|
263
309
|
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
);
|
|
270
|
-
validatorFns[DATE_BEFORE_TODAY] = (value, args, form) => {
|
|
310
|
+
var DATE_BEFORE_TODAY = "validator/DATE_BEFORE_TODAY";
|
|
311
|
+
var DATE_BEFORE_TODAY_ERROR = "error/DATE_BEFORE_TODAY";
|
|
312
|
+
var dateBeforeToday = createValidator(DATE_BEFORE_TODAY, DATE_BEFORE_TODAY_ERROR);
|
|
313
|
+
|
|
314
|
+
validatorFns[DATE_BEFORE_TODAY] = function (value, args, form) {
|
|
271
315
|
if (value === "") {
|
|
272
316
|
return true;
|
|
273
317
|
}
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
318
|
+
|
|
319
|
+
var dateFormat = args[0];
|
|
320
|
+
var unit = args[1];
|
|
321
|
+
var inclusive = args[2] || false;
|
|
277
322
|
|
|
278
323
|
if (dateFormat == undefined || unit == undefined) {
|
|
279
|
-
throw new Error(
|
|
280
|
-
"Date format and unit need to be defined for dateBeforeToday, one or both are undefined"
|
|
281
|
-
);
|
|
324
|
+
throw new Error("Date format and unit need to be defined for dateBeforeToday, one or both are undefined");
|
|
282
325
|
}
|
|
283
|
-
|
|
284
|
-
|
|
326
|
+
|
|
327
|
+
var now = dayjs();
|
|
328
|
+
var dateValue = dayjs(value, dateFormat);
|
|
285
329
|
|
|
286
330
|
if (inclusive === true) {
|
|
287
331
|
return dateValue.isSameOrBefore(now, unit);
|
|
288
332
|
}
|
|
333
|
+
|
|
289
334
|
return dateValue.isBefore(now, unit);
|
|
290
335
|
};
|
|
291
336
|
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
);
|
|
298
|
-
validatorFns[DATE_AFTER_TODAY] = (value, args, form) => {
|
|
337
|
+
var DATE_AFTER_TODAY = "validator/DATE_AFTER_TODAY";
|
|
338
|
+
var DATE_AFTER_TODAY_ERROR = "error/DATE_AFTER_TODAY";
|
|
339
|
+
var dateAfterToday = createValidator(DATE_AFTER_TODAY, DATE_AFTER_TODAY_ERROR);
|
|
340
|
+
|
|
341
|
+
validatorFns[DATE_AFTER_TODAY] = function (value, args, form) {
|
|
299
342
|
if (value === "") {
|
|
300
343
|
return true;
|
|
301
344
|
}
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
345
|
+
|
|
346
|
+
var dateFormat = args[0];
|
|
347
|
+
var unit = args[1];
|
|
348
|
+
var inclusive = args[2] || false;
|
|
305
349
|
|
|
306
350
|
if (dateFormat == undefined || unit == undefined) {
|
|
307
|
-
throw new Error(
|
|
308
|
-
"Date format and unit need to be defined for dateAfterToday, one or both are undefined"
|
|
309
|
-
);
|
|
351
|
+
throw new Error("Date format and unit need to be defined for dateAfterToday, one or both are undefined");
|
|
310
352
|
}
|
|
311
|
-
|
|
312
|
-
|
|
353
|
+
|
|
354
|
+
var now = dayjs();
|
|
355
|
+
var dateValue = dayjs(value, dateFormat);
|
|
313
356
|
|
|
314
357
|
if (inclusive === true) {
|
|
315
358
|
return dateValue.isSameOrAfter(now, unit);
|
|
316
359
|
}
|
|
360
|
+
|
|
317
361
|
return dateValue.isAfter(now, unit);
|
|
318
362
|
};
|
|
319
363
|
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
);
|
|
326
|
-
validatorFns[IS_VALID_MONTH] = (value, args, form) => {
|
|
364
|
+
var IS_VALID_MONTH = "validator/IS_VALID_MONTH";
|
|
365
|
+
var IS_VALID_MONTH_ERROR = "error/IS_VALID_MONTH";
|
|
366
|
+
var isValidMonth = createValidator(IS_VALID_MONTH, IS_VALID_MONTH_ERROR);
|
|
367
|
+
|
|
368
|
+
validatorFns[IS_VALID_MONTH] = function (value, args, form) {
|
|
327
369
|
if (value === "") {
|
|
328
370
|
return true;
|
|
329
|
-
}
|
|
330
|
-
// Function takes one argument representing the character position
|
|
371
|
+
} // Function takes one argument representing the character position
|
|
331
372
|
// In a date string to identify where the month is
|
|
332
373
|
// Eg "10/21/2021" - start position is 0
|
|
333
374
|
// Or "18/03/1990" - start position is 3
|
|
334
375
|
// Only works with two digit months (01, 02, 03, etc)
|
|
335
|
-
|
|
336
|
-
|
|
376
|
+
|
|
377
|
+
|
|
378
|
+
var monthStartPosition = parseInt(args[0]);
|
|
379
|
+
var monthEndPosition = monthStartPosition + 2;
|
|
380
|
+
|
|
337
381
|
if (monthStartPosition === NaN) {
|
|
338
382
|
throw new Error("Month start position has to be a valid integer string");
|
|
339
383
|
}
|
|
340
|
-
|
|
384
|
+
|
|
385
|
+
var month = parseInt(value.slice(monthStartPosition, monthEndPosition));
|
|
386
|
+
|
|
341
387
|
if (month === NaN) {
|
|
342
388
|
return false;
|
|
343
389
|
}
|
|
390
|
+
|
|
344
391
|
return month >= 1 && month <= 12;
|
|
345
392
|
};
|
|
346
393
|
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
394
|
+
var MATCHES_REGEX = "validator/MATCHES_REGEX";
|
|
395
|
+
var MATCHES_REGEX_ERROR = "error/MATCHES_REGEX";
|
|
396
|
+
var matchesRegex = createValidator(MATCHES_REGEX, MATCHES_REGEX_ERROR);
|
|
397
|
+
|
|
398
|
+
validatorFns[MATCHES_REGEX] = function (value, args, form) {
|
|
351
399
|
if (value === "") {
|
|
352
400
|
return true;
|
|
353
401
|
}
|
|
402
|
+
|
|
354
403
|
return new RegExp(args[0]).test(value); // new RexExp never throws an error, no matter the input
|
|
355
|
-
};
|
|
404
|
+
}; // based on http://www.brainjar.com/js/validation/
|
|
405
|
+
|
|
406
|
+
|
|
407
|
+
var IS_ROUTING_NUMBER = "validator/IS_ROUTING_NUMBER";
|
|
408
|
+
var IS_ROUTING_NUMBER_ERROR = "error/IS_ROUTING_NUMBER";
|
|
409
|
+
var isRoutingNumber = createValidator(IS_ROUTING_NUMBER, IS_ROUTING_NUMBER_ERROR);
|
|
356
410
|
|
|
357
|
-
|
|
358
|
-
const IS_ROUTING_NUMBER = "validator/IS_ROUTING_NUMBER";
|
|
359
|
-
const IS_ROUTING_NUMBER_ERROR = "error/IS_ROUTING_NUMBER";
|
|
360
|
-
const isRoutingNumber = createValidator(
|
|
361
|
-
IS_ROUTING_NUMBER,
|
|
362
|
-
IS_ROUTING_NUMBER_ERROR
|
|
363
|
-
);
|
|
364
|
-
validatorFns[IS_ROUTING_NUMBER] = (value, args, form) => {
|
|
411
|
+
validatorFns[IS_ROUTING_NUMBER] = function (value, args, form) {
|
|
365
412
|
if (value === "") {
|
|
366
413
|
return true;
|
|
367
414
|
}
|
|
415
|
+
|
|
368
416
|
if (value.length != 9) {
|
|
369
417
|
return false;
|
|
370
418
|
}
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
419
|
+
|
|
420
|
+
var sum = value.split("").map(function (ch) {
|
|
421
|
+
return parseInt(ch);
|
|
422
|
+
}).reduce(function (acc, cur, idx) {
|
|
423
|
+
switch (idx % 3) {
|
|
424
|
+
case 0:
|
|
425
|
+
return acc + 3 * cur;
|
|
426
|
+
|
|
427
|
+
case 1:
|
|
428
|
+
return acc + 7 * cur;
|
|
429
|
+
|
|
430
|
+
case 2:
|
|
431
|
+
return acc + 1 * cur;
|
|
432
|
+
}
|
|
433
|
+
}, 0);
|
|
384
434
|
return sum != 0 && sum % 10 == 0;
|
|
385
435
|
};
|
|
386
436
|
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
437
|
+
var HAS_NUMBER = "validator/HAS_NUMBER";
|
|
438
|
+
var HAS_NUMBER_ERROR = "error/HAS_NUMBER";
|
|
439
|
+
var hasNumber = createValidator(HAS_NUMBER, HAS_NUMBER_ERROR);
|
|
440
|
+
|
|
441
|
+
validatorFns[HAS_NUMBER] = function (value, args, form) {
|
|
391
442
|
if (value === "") {
|
|
392
443
|
return true;
|
|
393
444
|
}
|
|
445
|
+
|
|
394
446
|
return new RegExp(/[0-9]/).test(value);
|
|
395
447
|
};
|
|
396
448
|
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
);
|
|
403
|
-
validatorFns[HAS_LOWERCASE_LETTER] = (value, args, form) => {
|
|
449
|
+
var HAS_LOWERCASE_LETTER = "validator/HAS_LOWERCASE_LETTER";
|
|
450
|
+
var HAS_LOWERCASE_LETTER_ERROR = "error/HAS_LOWERCASE_LETTER";
|
|
451
|
+
var hasLowercaseLetter = createValidator(HAS_LOWERCASE_LETTER, HAS_LOWERCASE_LETTER_ERROR);
|
|
452
|
+
|
|
453
|
+
validatorFns[HAS_LOWERCASE_LETTER] = function (value, args, form) {
|
|
404
454
|
if (value === "") {
|
|
405
455
|
return true;
|
|
406
456
|
}
|
|
457
|
+
|
|
407
458
|
return new RegExp(/[a-z]/).test(value);
|
|
408
459
|
};
|
|
409
460
|
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
);
|
|
416
|
-
validatorFns[HAS_UPPERCASE_LETTER] = (value, args, form) => {
|
|
461
|
+
var HAS_UPPERCASE_LETTER = "validator/HAS_UPPERCASE_LETTER";
|
|
462
|
+
var HAS_UPPERCASE_LETTER_ERROR = "error/HAS_UPPERCASE_LETTER";
|
|
463
|
+
var hasUppercaseLetter = createValidator(HAS_UPPERCASE_LETTER, HAS_UPPERCASE_LETTER_ERROR);
|
|
464
|
+
|
|
465
|
+
validatorFns[HAS_UPPERCASE_LETTER] = function (value, args, form) {
|
|
417
466
|
if (value === "") {
|
|
418
467
|
return true;
|
|
419
468
|
}
|
|
469
|
+
|
|
420
470
|
return new RegExp(/[A-Z]/).test(value);
|
|
421
471
|
};
|
|
422
472
|
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
);
|
|
429
|
-
validatorFns[HAS_SPECIAL_CHARACTER] = (value, args, form) => {
|
|
473
|
+
var HAS_SPECIAL_CHARACTER = "validator/HAS_SPECIAL_CHARACTER";
|
|
474
|
+
var HAS_SPECIAL_CHARACTER_ERROR = "error/HAS_SPECIAL_CHARACTER";
|
|
475
|
+
var hasSpecialCharacter = createValidator(HAS_SPECIAL_CHARACTER, HAS_SPECIAL_CHARACTER_ERROR);
|
|
476
|
+
|
|
477
|
+
validatorFns[HAS_SPECIAL_CHARACTER] = function (value, args, form) {
|
|
430
478
|
if (value === "") {
|
|
431
479
|
return true;
|
|
432
480
|
}
|
|
481
|
+
|
|
433
482
|
return new RegExp(/[!@#$%^&*.?]/).test(value);
|
|
434
483
|
};
|
|
435
484
|
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
);
|
|
442
|
-
validatorFns[IS_PROBABLY_EMAIL] = (value, args, form) => {
|
|
485
|
+
var IS_PROBABLY_EMAIL = "validator/IS_PROBABLY_EMAIL";
|
|
486
|
+
var IS_PROBABLY_EMAIL_ERROR = "error/IS_PROBABLY_EMAIL";
|
|
487
|
+
var isProbablyEmail = createValidator(IS_PROBABLY_EMAIL, IS_PROBABLY_EMAIL_ERROR);
|
|
488
|
+
|
|
489
|
+
validatorFns[IS_PROBABLY_EMAIL] = function (value, args, form) {
|
|
443
490
|
if (value === "") {
|
|
444
491
|
return true;
|
|
445
492
|
}
|
|
493
|
+
|
|
446
494
|
return new RegExp(/^\S+@\S+\.\S+$/).test(value);
|
|
447
495
|
};
|
|
448
496
|
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
createFormState)`;
|
|
497
|
+
var runValidatorErrorMessage = function runValidatorErrorMessage(type) {
|
|
498
|
+
return type + " was passed to runValidator, but that validator type does not exist. \n Please check that you are only calling validator creator functions exported from \n redux-freeform in your form config and that you didn't forget to \n invoke the validator creator (you cannot pass the functions themselves to \n createFormState)";
|
|
499
|
+
};
|
|
500
|
+
var runValidator = function runValidator(validator, value, form) {
|
|
501
|
+
var validatorFn = validatorFns[validator.type];
|
|
455
502
|
|
|
456
|
-
const runValidator = (validator, value, form) => {
|
|
457
|
-
const validatorFn = validatorFns[validator.type];
|
|
458
503
|
if (validatorFn === undefined) {
|
|
459
504
|
throw new Error(runValidatorErrorMessage(validator.type));
|
|
460
505
|
}
|
|
506
|
+
|
|
461
507
|
return validatorFn(value, validator.args, form) ? null : validator.error;
|
|
462
508
|
};
|
|
463
509
|
|
|
464
|
-
|
|
465
|
-
return validators
|
|
466
|
-
|
|
467
|
-
|
|
510
|
+
var _computeErrors = function _computeErrors(fieldName, form, validators) {
|
|
511
|
+
return validators.map(function (v) {
|
|
512
|
+
return runValidator(v, form[fieldName].rawValue, form);
|
|
513
|
+
}).filter(function (x) {
|
|
514
|
+
return x !== null;
|
|
515
|
+
});
|
|
468
516
|
};
|
|
469
517
|
|
|
470
|
-
|
|
471
|
-
|
|
518
|
+
var computeConstraints = function computeConstraints(fieldName, form) {
|
|
519
|
+
var constraints = form[fieldName].constraints;
|
|
472
520
|
return _computeErrors(fieldName, form, constraints);
|
|
473
521
|
};
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
const validators = form[fieldName].validators;
|
|
522
|
+
var computeErrors = function computeErrors(fieldName, form) {
|
|
523
|
+
var validators = form[fieldName].validators;
|
|
477
524
|
return _computeErrors(fieldName, form, validators);
|
|
478
525
|
};
|
|
479
526
|
|
|
@@ -693,7 +740,7 @@ function get(state, prop) {
|
|
|
693
740
|
return value;
|
|
694
741
|
}
|
|
695
742
|
|
|
696
|
-
function set
|
|
743
|
+
function set(state, prop, value) {
|
|
697
744
|
assertUnrevoked(state);
|
|
698
745
|
state.assigned[prop] = true;
|
|
699
746
|
|
|
@@ -744,8 +791,8 @@ function proxyProperty(draft, prop, enumerable) {
|
|
|
744
791
|
return get(this[DRAFT_STATE], prop);
|
|
745
792
|
},
|
|
746
793
|
|
|
747
|
-
set: function set$1
|
|
748
|
-
set
|
|
794
|
+
set: function set$1(value) {
|
|
795
|
+
set(this[DRAFT_STATE], prop, value);
|
|
749
796
|
}
|
|
750
797
|
|
|
751
798
|
};
|
|
@@ -926,7 +973,7 @@ var objectTraps = {
|
|
|
926
973
|
return Reflect.ownKeys(source$1(target));
|
|
927
974
|
},
|
|
928
975
|
|
|
929
|
-
set: set$1
|
|
976
|
+
set: set$1,
|
|
930
977
|
deleteProperty: deleteProperty,
|
|
931
978
|
getOwnPropertyDescriptor: getOwnPropertyDescriptor,
|
|
932
979
|
|
|
@@ -1004,7 +1051,7 @@ function get$1(state, prop) {
|
|
|
1004
1051
|
return drafts[prop] = createProxy$1(value, state);
|
|
1005
1052
|
}
|
|
1006
1053
|
|
|
1007
|
-
function set$1
|
|
1054
|
+
function set$1(state, prop, value) {
|
|
1008
1055
|
if (!state.modified) {
|
|
1009
1056
|
var baseValue = peek$1(state.base, prop); // Optimize based on value's truthiness. Truthy values are guaranteed to
|
|
1010
1057
|
// never be undefined, so we can avoid the `in` operator. Lastly, truthy
|
|
@@ -1611,127 +1658,179 @@ immer.createDraft.bind(immer);
|
|
|
1611
1658
|
|
|
1612
1659
|
immer.finishDraft.bind(immer);
|
|
1613
1660
|
|
|
1614
|
-
|
|
1615
|
-
|
|
1616
|
-
|
|
1617
|
-
|
|
1661
|
+
var createInitialState = function createInitialState(formConfig) {
|
|
1662
|
+
var initialForm = {};
|
|
1663
|
+
var formConfigKeys = Object.keys(formConfig);
|
|
1664
|
+
|
|
1665
|
+
for (var _i = 0, _formConfigKeys = formConfigKeys; _i < _formConfigKeys.length; _i++) {
|
|
1666
|
+
var formKey = _formConfigKeys[_i];
|
|
1618
1667
|
initialForm[formKey] = {
|
|
1619
1668
|
dirty: false,
|
|
1620
1669
|
rawValue: formConfig[formKey].defaultValue || "",
|
|
1621
1670
|
validators: formConfig[formKey].validators || [],
|
|
1622
1671
|
constraints: formConfig[formKey].constraints || []
|
|
1623
1672
|
};
|
|
1624
|
-
}
|
|
1625
|
-
// Because validators require the entire form we have to do a
|
|
1673
|
+
} // Because validators require the entire form we have to do a
|
|
1626
1674
|
// second pass to add errors once the initial form has been
|
|
1627
1675
|
// constructed
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
|
|
1676
|
+
|
|
1677
|
+
|
|
1678
|
+
for (var _i2 = 0, _formConfigKeys2 = formConfigKeys; _i2 < _formConfigKeys2.length; _i2++) {
|
|
1679
|
+
var _formKey = _formConfigKeys2[_i2];
|
|
1680
|
+
var errors = computeErrors(_formKey, initialForm);
|
|
1681
|
+
initialForm[_formKey].errors = errors;
|
|
1682
|
+
initialForm[_formKey].hasErrors = errors.length > 0;
|
|
1632
1683
|
}
|
|
1684
|
+
|
|
1633
1685
|
return initialForm;
|
|
1634
1686
|
};
|
|
1687
|
+
var SET = "field/SET";
|
|
1688
|
+
|
|
1689
|
+
var _set = function set(fieldName) {
|
|
1690
|
+
return function (value) {
|
|
1691
|
+
return {
|
|
1692
|
+
type: SET,
|
|
1693
|
+
payload: {
|
|
1694
|
+
fieldName: fieldName,
|
|
1695
|
+
value: value
|
|
1696
|
+
}
|
|
1697
|
+
};
|
|
1698
|
+
};
|
|
1699
|
+
};
|
|
1700
|
+
var CLEAR = "form/CLEAR";
|
|
1635
1701
|
|
|
1636
|
-
|
|
1637
|
-
|
|
1638
|
-
|
|
1639
|
-
|
|
1640
|
-
}
|
|
1641
|
-
|
|
1642
|
-
|
|
1643
|
-
|
|
1702
|
+
var _clear = function clear() {
|
|
1703
|
+
return {
|
|
1704
|
+
type: CLEAR
|
|
1705
|
+
};
|
|
1706
|
+
};
|
|
1707
|
+
var ADD_VALIDATOR = "field/ADD_VALIDATOR";
|
|
1708
|
+
|
|
1709
|
+
var _addValidator = function addValidator(fieldName) {
|
|
1710
|
+
return function (validator) {
|
|
1711
|
+
return {
|
|
1712
|
+
type: ADD_VALIDATOR,
|
|
1713
|
+
payload: {
|
|
1714
|
+
fieldName: fieldName,
|
|
1715
|
+
validator: validator
|
|
1716
|
+
}
|
|
1717
|
+
};
|
|
1718
|
+
};
|
|
1719
|
+
};
|
|
1720
|
+
var createFormReducer = function createFormReducer(formConfig) {
|
|
1721
|
+
return function (state, action) {
|
|
1722
|
+
if (state === void 0) {
|
|
1723
|
+
state = createInitialState(formConfig);
|
|
1724
|
+
}
|
|
1644
1725
|
|
|
1645
|
-
|
|
1646
|
-
|
|
1647
|
-
|
|
1648
|
-
|
|
1649
|
-
|
|
1726
|
+
switch (action.type) {
|
|
1727
|
+
case SET:
|
|
1728
|
+
var changedFieldName = action.payload.fieldName;
|
|
1729
|
+
var newRawValue = action.payload.value;
|
|
1730
|
+
return produce(state, function (draftState) {
|
|
1731
|
+
var originalValue = draftState[changedFieldName].rawValue;
|
|
1732
|
+
draftState[changedFieldName].rawValue = newRawValue;
|
|
1733
|
+
|
|
1734
|
+
if (computeConstraints(changedFieldName, draftState).length > 0) {
|
|
1735
|
+
// If the change violates constraints, revert the change
|
|
1736
|
+
draftState[changedFieldName].rawValue = originalValue;
|
|
1737
|
+
return draftState;
|
|
1738
|
+
}
|
|
1739
|
+
|
|
1740
|
+
var fields = Object.entries(draftState);
|
|
1741
|
+
|
|
1742
|
+
for (var _i3 = 0, _fields = fields; _i3 < _fields.length; _i3++) {
|
|
1743
|
+
var entry = _fields[_i3];
|
|
1744
|
+
var fieldName = entry[0];
|
|
1745
|
+
var field = entry[1];
|
|
1746
|
+
var errors = computeErrors(fieldName, draftState);
|
|
1747
|
+
var dirty = fieldName === changedFieldName ? true : field.dirty;
|
|
1748
|
+
draftState[fieldName].errors = errors;
|
|
1749
|
+
draftState[fieldName].dirty = dirty;
|
|
1750
|
+
draftState[fieldName].hasErrors = errors.length > 0;
|
|
1751
|
+
}
|
|
1752
|
+
});
|
|
1650
1753
|
|
|
1651
|
-
|
|
1652
|
-
|
|
1653
|
-
|
|
1654
|
-
|
|
1655
|
-
|
|
1656
|
-
|
|
1657
|
-
|
|
1658
|
-
|
|
1659
|
-
|
|
1660
|
-
|
|
1661
|
-
|
|
1662
|
-
|
|
1663
|
-
|
|
1664
|
-
|
|
1665
|
-
|
|
1666
|
-
|
|
1667
|
-
|
|
1754
|
+
case CLEAR:
|
|
1755
|
+
return createInitialState(formConfig);
|
|
1756
|
+
|
|
1757
|
+
case ADD_VALIDATOR:
|
|
1758
|
+
var fieldWithOverride = action.payload.fieldName;
|
|
1759
|
+
var newValidator = action.payload.validator;
|
|
1760
|
+
return produce(state, function (draftState) {
|
|
1761
|
+
draftState[fieldWithOverride].validators.push(newValidator);
|
|
1762
|
+
var fields = Object.entries(draftState);
|
|
1763
|
+
|
|
1764
|
+
for (var _i4 = 0, _fields2 = fields; _i4 < _fields2.length; _i4++) {
|
|
1765
|
+
var entry = _fields2[_i4];
|
|
1766
|
+
var fieldName = entry[0];
|
|
1767
|
+
var field = entry[1];
|
|
1768
|
+
var errors = computeErrors(fieldName, draftState);
|
|
1769
|
+
var dirty = field.dirty;
|
|
1770
|
+
draftState[fieldName].errors = errors;
|
|
1771
|
+
draftState[fieldName].dirty = dirty;
|
|
1772
|
+
draftState[fieldName].hasErrors = errors.length > 0;
|
|
1773
|
+
}
|
|
1774
|
+
});
|
|
1668
1775
|
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
let errors = computeErrors(fieldName, draftState);
|
|
1674
|
-
let dirty = fieldName === changedFieldName ? true : field.dirty;
|
|
1675
|
-
draftState[fieldName].errors = errors;
|
|
1676
|
-
draftState[fieldName].dirty = dirty;
|
|
1677
|
-
draftState[fieldName].hasErrors = errors.length > 0;
|
|
1678
|
-
}
|
|
1679
|
-
});
|
|
1680
|
-
case CLEAR:
|
|
1681
|
-
return createInitialState(formConfig);
|
|
1682
|
-
case ADD_VALIDATOR:
|
|
1683
|
-
const fieldWithOverride = action.payload.fieldName;
|
|
1684
|
-
const newValidator = action.payload.validator;
|
|
1685
|
-
|
|
1686
|
-
return produce(state, draftState => {
|
|
1687
|
-
draftState[fieldWithOverride].validators.push(newValidator);
|
|
1688
|
-
const fields = Object.entries(draftState);
|
|
1689
|
-
for (let entry of fields) {
|
|
1690
|
-
let fieldName = entry[0];
|
|
1691
|
-
let field = entry[1];
|
|
1692
|
-
let errors = computeErrors(fieldName, draftState);
|
|
1693
|
-
let dirty = field.dirty;
|
|
1694
|
-
draftState[fieldName].errors = errors;
|
|
1695
|
-
draftState[fieldName].dirty = dirty;
|
|
1696
|
-
draftState[fieldName].hasErrors = errors.length > 0;
|
|
1697
|
-
}
|
|
1698
|
-
});
|
|
1699
|
-
default:
|
|
1700
|
-
return state;
|
|
1701
|
-
}
|
|
1776
|
+
default:
|
|
1777
|
+
return state;
|
|
1778
|
+
}
|
|
1779
|
+
};
|
|
1702
1780
|
};
|
|
1703
|
-
|
|
1704
|
-
const createMapDispatchToProps = formConfig => {
|
|
1781
|
+
var createMapDispatchToProps = function createMapDispatchToProps(formConfig) {
|
|
1705
1782
|
// Do memo-ization
|
|
1706
|
-
|
|
1707
|
-
|
|
1708
|
-
return dispatch
|
|
1783
|
+
var cachedDispatch;
|
|
1784
|
+
var cacheValue;
|
|
1785
|
+
return function (dispatch) {
|
|
1709
1786
|
if (dispatch == cachedDispatch) {
|
|
1710
1787
|
return cacheValue;
|
|
1711
1788
|
}
|
|
1712
|
-
|
|
1789
|
+
|
|
1790
|
+
var dispatchObj = {};
|
|
1713
1791
|
dispatchObj.fields = {};
|
|
1714
|
-
|
|
1715
|
-
|
|
1792
|
+
var keys = Object.keys(formConfig);
|
|
1793
|
+
|
|
1794
|
+
var _loop = function _loop() {
|
|
1795
|
+
var fieldName = _keys[_i5];
|
|
1716
1796
|
dispatchObj.fields[fieldName] = {
|
|
1717
|
-
set:
|
|
1718
|
-
|
|
1797
|
+
set: function set(value) {
|
|
1798
|
+
return dispatch(_set(fieldName)(value));
|
|
1799
|
+
},
|
|
1800
|
+
addValidator: function addValidator(validator) {
|
|
1801
|
+
return dispatch(_addValidator(fieldName)(validator));
|
|
1802
|
+
}
|
|
1719
1803
|
};
|
|
1804
|
+
};
|
|
1805
|
+
|
|
1806
|
+
for (var _i5 = 0, _keys = keys; _i5 < _keys.length; _i5++) {
|
|
1807
|
+
_loop();
|
|
1720
1808
|
}
|
|
1721
|
-
|
|
1809
|
+
|
|
1810
|
+
dispatchObj.form = {
|
|
1811
|
+
clear: function clear() {
|
|
1812
|
+
return dispatch(_clear());
|
|
1813
|
+
}
|
|
1814
|
+
};
|
|
1722
1815
|
cachedDispatch = dispatch;
|
|
1723
|
-
cacheValue = {
|
|
1816
|
+
cacheValue = {
|
|
1817
|
+
actions: dispatchObj
|
|
1818
|
+
};
|
|
1724
1819
|
return cacheValue;
|
|
1725
1820
|
};
|
|
1726
1821
|
};
|
|
1727
|
-
|
|
1728
|
-
|
|
1729
|
-
|
|
1730
|
-
|
|
1731
|
-
|
|
1732
|
-
|
|
1733
|
-
|
|
1734
|
-
|
|
1822
|
+
var mapStateToProps = function mapStateToProps(state) {
|
|
1823
|
+
return {
|
|
1824
|
+
fields: state
|
|
1825
|
+
};
|
|
1826
|
+
};
|
|
1827
|
+
var createFormState = function createFormState(formConfig) {
|
|
1828
|
+
return {
|
|
1829
|
+
reducer: createFormReducer(formConfig),
|
|
1830
|
+
mapDispatchToProps: createMapDispatchToProps(formConfig),
|
|
1831
|
+
mapStateToProps: mapStateToProps
|
|
1832
|
+
};
|
|
1833
|
+
};
|
|
1735
1834
|
|
|
1736
1835
|
exports.createFormState = createFormState;
|
|
1737
1836
|
exports.dateAfterToday = dateAfterToday;
|