redux-freeform 5.1.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 +532 -394
- package/dist/redux-freeform.esm.js +532 -395
- package/dist/redux-freeform.umd.js +522 -399
- package/package.json +9 -7
|
@@ -2,440 +2,525 @@
|
|
|
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
|
+
}
|
|
9
28
|
|
|
10
|
-
|
|
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];
|
|
11
33
|
|
|
12
|
-
|
|
13
|
-
return module = { exports: {} }, fn(module, module.exports), module.exports;
|
|
34
|
+
return arr2;
|
|
14
35
|
}
|
|
15
36
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
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);
|
|
19
40
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
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
|
+
};
|
|
67
|
+
|
|
68
|
+
var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
|
|
69
|
+
|
|
70
|
+
var dayjs_min = {exports: {}};
|
|
71
|
+
|
|
72
|
+
(function (module, exports) {
|
|
73
|
+
!function(t,e){module.exports=e();}(commonjsGlobal,(function(){var t=1e3,e=6e4,n=36e5,r="millisecond",i="second",s="minute",u="hour",a="day",o="week",f="month",h="quarter",c="year",d="date",$="Invalid Date",l=/^(\d{4})[-/]?(\d{1,2})?[-/]?(\d{0,2})[Tt\s]*(\d{1,2})?:?(\d{1,2})?:?(\d{1,2})?[.:]?(\d+)?$/,y=/\[([^\]]+)]|Y{1,4}|M{1,4}|D{1,2}|d{1,4}|H{1,2}|h{1,2}|a|A|m{1,2}|s{1,2}|Z{1,2}|SSS/g,M={name:"en",weekdays:"Sunday_Monday_Tuesday_Wednesday_Thursday_Friday_Saturday".split("_"),months:"January_February_March_April_May_June_July_August_September_October_November_December".split("_")},m=function(t,e,n){var r=String(t);return !r||r.length>=e?t:""+Array(e+1-r.length).join(n)+t},g={s:m,z:function(t){var e=-t.utcOffset(),n=Math.abs(e),r=Math.floor(n/60),i=n%60;return (e<=0?"+":"-")+m(r,2,"0")+":"+m(i,2,"0")},m:function t(e,n){if(e.date()<n.date())return -t(n,e);var r=12*(n.year()-e.year())+(n.month()-e.month()),i=e.clone().add(r,f),s=n-i<0,u=e.clone().add(r+(s?-1:1),f);return +(-(r+(n-i)/(s?i-u:u-i))||0)},a:function(t){return t<0?Math.ceil(t)||0:Math.floor(t)},p:function(t){return {M:f,y:c,w:o,d:a,D:d,h:u,m:s,s:i,ms:r,Q:h}[t]||String(t||"").toLowerCase().replace(/s$/,"")},u:function(t){return void 0===t}},D="en",v={};v[D]=M;var p=function(t){return t instanceof _},S=function(t,e,n){var r;if(!t)return D;if("string"==typeof t)v[t]&&(r=t),e&&(v[t]=e,r=t);else {var i=t.name;v[i]=t,r=i;}return !n&&r&&(D=r),r||!n&&D},w=function(t,e){if(p(t))return t.clone();var n="object"==typeof e?e:{};return n.date=t,n.args=arguments,new _(n)},O=g;O.l=S,O.i=p,O.w=function(t,e){return w(t,{locale:e.$L,utc:e.$u,x:e.$x,$offset:e.$offset})};var _=function(){function M(t){this.$L=S(t.locale,null,!0),this.parse(t);}var m=M.prototype;return m.parse=function(t){this.$d=function(t){var e=t.date,n=t.utc;if(null===e)return new Date(NaN);if(O.u(e))return new Date;if(e instanceof Date)return new Date(e);if("string"==typeof e&&!/Z$/i.test(e)){var r=e.match(l);if(r){var i=r[2]-1||0,s=(r[7]||"0").substring(0,3);return n?new Date(Date.UTC(r[1],i,r[3]||1,r[4]||0,r[5]||0,r[6]||0,s)):new Date(r[1],i,r[3]||1,r[4]||0,r[5]||0,r[6]||0,s)}}return new Date(e)}(t),this.$x=t.x||{},this.init();},m.init=function(){var t=this.$d;this.$y=t.getFullYear(),this.$M=t.getMonth(),this.$D=t.getDate(),this.$W=t.getDay(),this.$H=t.getHours(),this.$m=t.getMinutes(),this.$s=t.getSeconds(),this.$ms=t.getMilliseconds();},m.$utils=function(){return O},m.isValid=function(){return !(this.$d.toString()===$)},m.isSame=function(t,e){var n=w(t);return this.startOf(e)<=n&&n<=this.endOf(e)},m.isAfter=function(t,e){return w(t)<this.startOf(e)},m.isBefore=function(t,e){return this.endOf(e)<w(t)},m.$g=function(t,e,n){return O.u(t)?this[e]:this.set(n,t)},m.unix=function(){return Math.floor(this.valueOf()/1e3)},m.valueOf=function(){return this.$d.getTime()},m.startOf=function(t,e){var n=this,r=!!O.u(e)||e,h=O.p(t),$=function(t,e){var i=O.w(n.$u?Date.UTC(n.$y,e,t):new Date(n.$y,e,t),n);return r?i:i.endOf(a)},l=function(t,e){return O.w(n.toDate()[t].apply(n.toDate("s"),(r?[0,0,0,0]:[23,59,59,999]).slice(e)),n)},y=this.$W,M=this.$M,m=this.$D,g="set"+(this.$u?"UTC":"");switch(h){case c:return r?$(1,0):$(31,11);case f:return r?$(1,M):$(0,M+1);case o:var D=this.$locale().weekStart||0,v=(y<D?y+7:y)-D;return $(r?m-v:m+(6-v),M);case a:case d:return l(g+"Hours",0);case u:return l(g+"Minutes",1);case s:return l(g+"Seconds",2);case i:return l(g+"Milliseconds",3);default:return this.clone()}},m.endOf=function(t){return this.startOf(t,!1)},m.$set=function(t,e){var n,o=O.p(t),h="set"+(this.$u?"UTC":""),$=(n={},n[a]=h+"Date",n[d]=h+"Date",n[f]=h+"Month",n[c]=h+"FullYear",n[u]=h+"Hours",n[s]=h+"Minutes",n[i]=h+"Seconds",n[r]=h+"Milliseconds",n)[o],l=o===a?this.$D+(e-this.$W):e;if(o===f||o===c){var y=this.clone().set(d,1);y.$d[$](l),y.init(),this.$d=y.set(d,Math.min(this.$D,y.daysInMonth())).$d;}else $&&this.$d[$](l);return this.init(),this},m.set=function(t,e){return this.clone().$set(t,e)},m.get=function(t){return this[O.p(t)]()},m.add=function(r,h){var d,$=this;r=Number(r);var l=O.p(h),y=function(t){var e=w($);return O.w(e.date(e.date()+Math.round(t*r)),$)};if(l===f)return this.set(f,this.$M+r);if(l===c)return this.set(c,this.$y+r);if(l===a)return y(1);if(l===o)return y(7);var M=(d={},d[s]=e,d[u]=n,d[i]=t,d)[l]||1,m=this.$d.getTime()+r*M;return O.w(m,this)},m.subtract=function(t,e){return this.add(-1*t,e)},m.format=function(t){var e=this,n=this.$locale();if(!this.isValid())return n.invalidDate||$;var r=t||"YYYY-MM-DDTHH:mm:ssZ",i=O.z(this),s=this.$H,u=this.$m,a=this.$M,o=n.weekdays,f=n.months,h=function(t,n,i,s){return t&&(t[n]||t(e,r))||i[n].substr(0,s)},c=function(t){return O.s(s%12||12,t,"0")},d=n.meridiem||function(t,e,n){var r=t<12?"AM":"PM";return n?r.toLowerCase():r},l={YY:String(this.$y).slice(-2),YYYY:this.$y,M:a+1,MM:O.s(a+1,2,"0"),MMM:h(n.monthsShort,a,f,3),MMMM:h(f,a),D:this.$D,DD:O.s(this.$D,2,"0"),d:String(this.$W),dd:h(n.weekdaysMin,this.$W,o,2),ddd:h(n.weekdaysShort,this.$W,o,3),dddd:o[this.$W],H:String(s),HH:O.s(s,2,"0"),h:c(1),hh:c(2),a:d(s,u,!0),A:d(s,u,!1),m:String(u),mm:O.s(u,2,"0"),s:String(this.$s),ss:O.s(this.$s,2,"0"),SSS:O.s(this.$ms,3,"0"),Z:i};return r.replace(y,(function(t,e){return e||l[t]||i.replace(":","")}))},m.utcOffset=function(){return 15*-Math.round(this.$d.getTimezoneOffset()/15)},m.diff=function(r,d,$){var l,y=O.p(d),M=w(r),m=(M.utcOffset()-this.utcOffset())*e,g=this-M,D=O.m(this,M);return D=(l={},l[c]=D/12,l[f]=D,l[h]=D/3,l[o]=(g-m)/6048e5,l[a]=(g-m)/864e5,l[u]=g/n,l[s]=g/e,l[i]=g/t,l)[y]||g,$?D:O.a(D)},m.daysInMonth=function(){return this.endOf(f).$D},m.$locale=function(){return v[this.$L]},m.locale=function(t,e){if(!t)return this.$L;var n=this.clone(),r=S(t,e,!0);return r&&(n.$L=r),n},m.clone=function(){return O.w(this.$d,this)},m.toDate=function(){return new Date(this.valueOf())},m.toJSON=function(){return this.isValid()?this.toISOString():null},m.toISOString=function(){return this.$d.toISOString()},m.toString=function(){return this.$d.toUTCString()},M}(),b=_.prototype;return w.prototype=b,[["$ms",r],["$s",i],["$m",s],["$H",u],["$W",a],["$M",f],["$y",c],["$D",d]].forEach((function(t){b[t[1]]=function(e){return this.$g(e,t[0],t[1])};})),w.extend=function(t,e){return t.$i||(t(e,_,w),t.$i=!0),w},w.locale=S,w.isDayjs=p,w.unix=function(t){return w(1e3*t)},w.en=v[D],w.Ls=v,w.p={},w}));
|
|
74
|
+
}(dayjs_min));
|
|
75
|
+
|
|
76
|
+
var dayjs = dayjs_min.exports;
|
|
77
|
+
|
|
78
|
+
var customParseFormat$1 = {exports: {}};
|
|
23
79
|
|
|
24
|
-
|
|
80
|
+
(function (module, exports) {
|
|
81
|
+
!function(t,e){module.exports=e();}(commonjsGlobal,(function(){var t={LTS:"h:mm:ss A",LT:"h:mm A",L:"MM/DD/YYYY",LL:"MMMM D, YYYY",LLL:"MMMM D, YYYY h:mm A",LLLL:"dddd, MMMM D, YYYY h:mm A"},e=/(\[[^[]*\])|([-:/.()\s]+)|(A|a|YYYY|YY?|MM?M?M?|Do|DD?|hh?|HH?|mm?|ss?|S{1,3}|z|ZZ?)/g,n=/\d\d/,r=/\d\d?/,i=/\d*[^\s\d-_:/()]+/,o={},s=function(t){return (t=+t)+(t>68?1900:2e3)};var a=function(t){return function(e){this[t]=+e;}},f=[/[+-]\d\d:?(\d\d)?|Z/,function(t){(this.zone||(this.zone={})).offset=function(t){if(!t)return 0;if("Z"===t)return 0;var e=t.match(/([+-]|\d\d)/g),n=60*e[1]+(+e[2]||0);return 0===n?0:"+"===e[0]?-n:n}(t);}],u=function(t){var e=o[t];return e&&(e.indexOf?e:e.s.concat(e.f))},h=function(t,e){var n,r=o.meridiem;if(r){for(var i=1;i<=24;i+=1)if(t.indexOf(r(i,0,e))>-1){n=i>12;break}}else n=t===(e?"pm":"PM");return n},d={A:[i,function(t){this.afternoon=h(t,!1);}],a:[i,function(t){this.afternoon=h(t,!0);}],S:[/\d/,function(t){this.milliseconds=100*+t;}],SS:[n,function(t){this.milliseconds=10*+t;}],SSS:[/\d{3}/,function(t){this.milliseconds=+t;}],s:[r,a("seconds")],ss:[r,a("seconds")],m:[r,a("minutes")],mm:[r,a("minutes")],H:[r,a("hours")],h:[r,a("hours")],HH:[r,a("hours")],hh:[r,a("hours")],D:[r,a("day")],DD:[n,a("day")],Do:[i,function(t){var e=o.ordinal,n=t.match(/\d+/);if(this.day=n[0],e)for(var r=1;r<=31;r+=1)e(r).replace(/\[|\]/g,"")===t&&(this.day=r);}],M:[r,a("month")],MM:[n,a("month")],MMM:[i,function(t){var e=u("months"),n=(u("monthsShort")||e.map((function(t){return t.substr(0,3)}))).indexOf(t)+1;if(n<1)throw new Error;this.month=n%12||n;}],MMMM:[i,function(t){var e=u("months").indexOf(t)+1;if(e<1)throw new Error;this.month=e%12||e;}],Y:[/[+-]?\d+/,a("year")],YY:[n,function(t){this.year=s(t);}],YYYY:[/\d{4}/,a("year")],Z:f,ZZ:f};function c(n){var r,i;r=n,i=o&&o.formats;for(var s=(n=r.replace(/(\[[^\]]+])|(LTS?|l{1,4}|L{1,4})/g,(function(e,n,r){var o=r&&r.toUpperCase();return n||i[r]||t[r]||i[o].replace(/(\[[^\]]+])|(MMMM|MM|DD|dddd)/g,(function(t,e,n){return e||n.slice(1)}))}))).match(e),a=s.length,f=0;f<a;f+=1){var u=s[f],h=d[u],c=h&&h[0],l=h&&h[1];s[f]=l?{regex:c,parser:l}:u.replace(/^\[|\]$/g,"");}return function(t){for(var e={},n=0,r=0;n<a;n+=1){var i=s[n];if("string"==typeof i)r+=i.length;else {var o=i.regex,f=i.parser,u=t.substr(r),h=o.exec(u)[0];f.call(e,h),t=t.replace(h,"");}}return function(t){var e=t.afternoon;if(void 0!==e){var n=t.hours;e?n<12&&(t.hours+=12):12===n&&(t.hours=0),delete t.afternoon;}}(e),e}}return function(t,e,n){n.p.customParseFormat=!0,t&&t.parseTwoDigitYear&&(s=t.parseTwoDigitYear);var r=e.prototype,i=r.parse;r.parse=function(t){var e=t.date,r=t.utc,s=t.args;this.$u=r;var a=s[1];if("string"==typeof a){var f=!0===s[2],u=!0===s[3],h=f||u,d=s[2];u&&(d=s[2]),o=this.$locale(),!f&&d&&(o=n.Ls[d]),this.$d=function(t,e,n){try{if(["x","X"].indexOf(e)>-1)return new Date(("X"===e?1e3:1)*t);var r=c(e)(t),i=r.year,o=r.month,s=r.day,a=r.hours,f=r.minutes,u=r.seconds,h=r.milliseconds,d=r.zone,l=new Date,m=s||(i||o?1:l.getDate()),M=i||l.getFullYear(),Y=0;i&&!o||(Y=o>0?o-1:l.getMonth());var p=a||0,v=f||0,D=u||0,g=h||0;return d?new Date(Date.UTC(M,Y,m,p,v,D,g+60*d.offset*1e3)):n?new Date(Date.UTC(M,Y,m,p,v,D,g)):new Date(M,Y,m,p,v,D,g)}catch(t){return new Date("")}}(e,a,r),this.init(),d&&!0!==d&&(this.$L=this.locale(d).$L),h&&e!=this.format(a)&&(this.$d=new Date("")),o={};}else if(a instanceof Array)for(var l=a.length,m=1;m<=l;m+=1){s[1]=a[m-1];var M=n.apply(this,s);if(M.isValid()){this.$d=M.$d,this.$L=M.$L,this.init();break}m===l&&(this.$d=new Date(""));}else i.call(this,t);};}}));
|
|
82
|
+
}(customParseFormat$1));
|
|
83
|
+
|
|
84
|
+
var customParseFormat = customParseFormat$1.exports;
|
|
85
|
+
|
|
86
|
+
var isSameOrBefore$1 = {exports: {}};
|
|
87
|
+
|
|
88
|
+
(function (module, exports) {
|
|
25
89
|
!function(e,i){module.exports=i();}(commonjsGlobal,(function(){return function(e,i){i.prototype.isSameOrBefore=function(e,i){return this.isSame(e,i)||this.isBefore(e,i)};}}));
|
|
26
|
-
});
|
|
90
|
+
}(isSameOrBefore$1));
|
|
91
|
+
|
|
92
|
+
var isSameOrBefore = isSameOrBefore$1.exports;
|
|
93
|
+
|
|
94
|
+
var isSameOrAfter$1 = {exports: {}};
|
|
27
95
|
|
|
28
|
-
|
|
96
|
+
(function (module, exports) {
|
|
29
97
|
!function(e,t){module.exports=t();}(commonjsGlobal,(function(){return function(e,t){t.prototype.isSameOrAfter=function(e,t){return this.isSame(e,t)||this.isAfter(e,t)};}}));
|
|
30
|
-
});
|
|
98
|
+
}(isSameOrAfter$1));
|
|
99
|
+
|
|
100
|
+
var isSameOrAfter = isSameOrAfter$1.exports;
|
|
31
101
|
|
|
32
|
-
|
|
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
|
+
};
|
|
33
114
|
|
|
34
|
-
const createValidator = (type, error) => {
|
|
35
|
-
let validator = (...args) => ({ type, args, error });
|
|
36
115
|
validator.error = error;
|
|
37
116
|
return validator;
|
|
38
117
|
};
|
|
39
118
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
119
|
+
dayjs.extend(customParseFormat);
|
|
120
|
+
dayjs.extend(isSameOrBefore);
|
|
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
|
+
};
|
|
146
|
+
|
|
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) {
|
|
68
152
|
if (value === "") {
|
|
69
153
|
return true;
|
|
70
154
|
}
|
|
155
|
+
|
|
71
156
|
return Number(value) < args[0];
|
|
72
157
|
};
|
|
73
158
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
NUMBER_LESS_THAN_OR_EQUAL_TO,
|
|
80
|
-
NUMBER_LESS_THAN_OR_EQUAL_TO_ERROR
|
|
81
|
-
);
|
|
82
|
-
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) {
|
|
83
164
|
if (value === "") {
|
|
84
165
|
return true;
|
|
85
166
|
}
|
|
167
|
+
|
|
86
168
|
return Number(value) <= args[0];
|
|
87
169
|
};
|
|
88
170
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
);
|
|
95
|
-
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) {
|
|
96
176
|
if (value === "") {
|
|
97
177
|
return true;
|
|
98
178
|
}
|
|
179
|
+
|
|
99
180
|
return Number(value) > args[0];
|
|
100
181
|
};
|
|
101
182
|
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
NUMBER_GREATER_THAN_OR_EQUAL_TO,
|
|
108
|
-
NUMBER_GREATER_THAN_OR_EQUAL_TO_ERROR
|
|
109
|
-
);
|
|
110
|
-
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) {
|
|
111
188
|
if (value === "") {
|
|
112
189
|
return true;
|
|
113
190
|
}
|
|
191
|
+
|
|
114
192
|
return Number(value) >= args[0];
|
|
115
193
|
};
|
|
116
194
|
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
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
|
+
|
|
205
|
+
if (dependentField === undefined) {
|
|
206
|
+
throw new Error(args[0] + " was passed to matchesField, but that field does not exist in the form");
|
|
128
207
|
}
|
|
129
|
-
|
|
208
|
+
|
|
209
|
+
return value === dependentFieldValue;
|
|
210
|
+
};
|
|
211
|
+
|
|
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
|
+
};
|
|
130
224
|
};
|
|
131
225
|
|
|
132
|
-
const validateWhenErrorMessage = type =>
|
|
133
|
-
`${type} was passed to validateWhen, but that validator type does not exist.
|
|
134
|
-
Please check that you are only calling validator creator functions exported from
|
|
135
|
-
redux-freeform in your form config and that you didn't forget to
|
|
136
|
-
invoke the validator creator (you cannot pass the functions themselves to
|
|
137
|
-
createFormState). Also make sure you aren't passing validateWhen() to validateWhen
|
|
138
|
-
as the primary validator.`;
|
|
139
|
-
|
|
140
|
-
const VALIDATE_WHEN = "validator/VALIDATE_WHEN";
|
|
141
|
-
const VALIDATE_WHEN_ERROR = "error/VALIDATE_WHEN";
|
|
142
|
-
const validateWhen = (
|
|
143
|
-
dependentValidator,
|
|
144
|
-
primaryValidator,
|
|
145
|
-
optionalFieldName
|
|
146
|
-
) => ({
|
|
147
|
-
type: VALIDATE_WHEN,
|
|
148
|
-
args: [dependentValidator, primaryValidator, optionalFieldName],
|
|
149
|
-
error: dependentValidator.error
|
|
150
|
-
});
|
|
151
226
|
validateWhen.error = VALIDATE_WHEN_ERROR;
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
) {
|
|
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") {
|
|
160
235
|
throw new Error(validateWhenErrorMessage(primaryValidator.type));
|
|
161
236
|
}
|
|
237
|
+
|
|
162
238
|
if (dependsOnOtherField && form[optionalFieldName] === undefined) {
|
|
163
|
-
throw new Error(
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
dependentValidator.args,
|
|
185
|
-
form
|
|
186
|
-
)
|
|
187
|
-
: 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
|
+
};
|
|
188
260
|
};
|
|
189
261
|
|
|
190
|
-
const validateSumErrorMessage = type =>
|
|
191
|
-
`${type} was passed to validateSum, but that validator type does not exist.
|
|
192
|
-
Please check that you are only calling validator creator functions exported from
|
|
193
|
-
redux-freeform in your form config and that you didn't forget to
|
|
194
|
-
invoke the validator creator (you cannot pass the functions themselves to
|
|
195
|
-
createFormState).`;
|
|
196
|
-
const VALIDATE_SUM = "validator/VALIDATE_SUM";
|
|
197
|
-
const VALIDATE_SUM_ERROR = "error/VALIDATE_SUM";
|
|
198
|
-
const validateSum = (validator, fieldNamesArray) => ({
|
|
199
|
-
type: VALIDATE_SUM,
|
|
200
|
-
args: [validator, fieldNamesArray],
|
|
201
|
-
error: validator.error
|
|
202
|
-
});
|
|
203
262
|
validateSum.error = VALIDATE_SUM_ERROR;
|
|
204
|
-
validatorFns[VALIDATE_SUM] = (value, args, form) => {
|
|
205
|
-
const [validator, fieldNamesArray] = args;
|
|
206
263
|
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
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") {
|
|
211
269
|
throw new Error(validateSumErrorMessage(validator.type));
|
|
212
270
|
}
|
|
213
271
|
|
|
214
|
-
for (
|
|
272
|
+
for (var _iterator = _createForOfIteratorHelperLoose(fieldNamesArray), _step; !(_step = _iterator()).done;) {
|
|
273
|
+
var fieldName = _step.value;
|
|
274
|
+
|
|
215
275
|
if (form[fieldName] === undefined) {
|
|
216
|
-
throw new Error(
|
|
217
|
-
`${fieldName} was passed to matchesField, but that field does not exist in the form`
|
|
218
|
-
);
|
|
276
|
+
throw new Error(fieldName + " was passed to matchesField, but that field does not exist in the form");
|
|
219
277
|
}
|
|
220
278
|
}
|
|
221
279
|
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
);
|
|
226
|
-
|
|
280
|
+
var sum = fieldNamesArray.reduce(function (acc, curr) {
|
|
281
|
+
return acc + Number(form[curr].rawValue);
|
|
282
|
+
}, Number(value));
|
|
227
283
|
return validatorFns[validator.type](sum, validator.args, form);
|
|
228
284
|
};
|
|
229
285
|
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
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) {
|
|
234
291
|
if (value === "") {
|
|
235
292
|
return true;
|
|
236
293
|
}
|
|
237
|
-
|
|
238
|
-
|
|
294
|
+
|
|
295
|
+
var min = args[0];
|
|
296
|
+
var max = args[1];
|
|
297
|
+
|
|
239
298
|
if (max == undefined || min == undefined) {
|
|
240
|
-
throw new Error(
|
|
241
|
-
"Max and min need to be defined for hasLength, both or one of them is undefined"
|
|
242
|
-
);
|
|
299
|
+
throw new Error("Max and min need to be defined for hasLength, both or one of them is undefined");
|
|
243
300
|
}
|
|
301
|
+
|
|
244
302
|
if (max < min) {
|
|
245
|
-
throw new Error(
|
|
246
|
-
"hasLength validator was passed a min greater than the max"
|
|
247
|
-
);
|
|
303
|
+
throw new Error("hasLength validator was passed a min greater than the max");
|
|
248
304
|
}
|
|
249
|
-
|
|
305
|
+
|
|
306
|
+
var valueLength = value.length;
|
|
250
307
|
return max >= valueLength && valueLength >= min;
|
|
251
308
|
};
|
|
252
309
|
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
);
|
|
259
|
-
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) {
|
|
260
315
|
if (value === "") {
|
|
261
316
|
return true;
|
|
262
317
|
}
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
318
|
+
|
|
319
|
+
var dateFormat = args[0];
|
|
320
|
+
var unit = args[1];
|
|
321
|
+
var inclusive = args[2] || false;
|
|
266
322
|
|
|
267
323
|
if (dateFormat == undefined || unit == undefined) {
|
|
268
|
-
throw new Error(
|
|
269
|
-
"Date format and unit need to be defined for dateBeforeToday, one or both are undefined"
|
|
270
|
-
);
|
|
324
|
+
throw new Error("Date format and unit need to be defined for dateBeforeToday, one or both are undefined");
|
|
271
325
|
}
|
|
272
|
-
|
|
273
|
-
|
|
326
|
+
|
|
327
|
+
var now = dayjs();
|
|
328
|
+
var dateValue = dayjs(value, dateFormat);
|
|
274
329
|
|
|
275
330
|
if (inclusive === true) {
|
|
276
331
|
return dateValue.isSameOrBefore(now, unit);
|
|
277
332
|
}
|
|
333
|
+
|
|
278
334
|
return dateValue.isBefore(now, unit);
|
|
279
335
|
};
|
|
280
336
|
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
);
|
|
287
|
-
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) {
|
|
288
342
|
if (value === "") {
|
|
289
343
|
return true;
|
|
290
344
|
}
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
345
|
+
|
|
346
|
+
var dateFormat = args[0];
|
|
347
|
+
var unit = args[1];
|
|
348
|
+
var inclusive = args[2] || false;
|
|
294
349
|
|
|
295
350
|
if (dateFormat == undefined || unit == undefined) {
|
|
296
|
-
throw new Error(
|
|
297
|
-
"Date format and unit need to be defined for dateAfterToday, one or both are undefined"
|
|
298
|
-
);
|
|
351
|
+
throw new Error("Date format and unit need to be defined for dateAfterToday, one or both are undefined");
|
|
299
352
|
}
|
|
300
|
-
|
|
301
|
-
|
|
353
|
+
|
|
354
|
+
var now = dayjs();
|
|
355
|
+
var dateValue = dayjs(value, dateFormat);
|
|
302
356
|
|
|
303
357
|
if (inclusive === true) {
|
|
304
358
|
return dateValue.isSameOrAfter(now, unit);
|
|
305
359
|
}
|
|
360
|
+
|
|
306
361
|
return dateValue.isAfter(now, unit);
|
|
307
362
|
};
|
|
308
363
|
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
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) {
|
|
313
369
|
if (value === "") {
|
|
314
370
|
return true;
|
|
371
|
+
} // Function takes one argument representing the character position
|
|
372
|
+
// In a date string to identify where the month is
|
|
373
|
+
// Eg "10/21/2021" - start position is 0
|
|
374
|
+
// Or "18/03/1990" - start position is 3
|
|
375
|
+
// Only works with two digit months (01, 02, 03, etc)
|
|
376
|
+
|
|
377
|
+
|
|
378
|
+
var monthStartPosition = parseInt(args[0]);
|
|
379
|
+
var monthEndPosition = monthStartPosition + 2;
|
|
380
|
+
|
|
381
|
+
if (monthStartPosition === NaN) {
|
|
382
|
+
throw new Error("Month start position has to be a valid integer string");
|
|
315
383
|
}
|
|
316
|
-
|
|
384
|
+
|
|
385
|
+
var month = parseInt(value.slice(monthStartPosition, monthEndPosition));
|
|
386
|
+
|
|
387
|
+
if (month === NaN) {
|
|
388
|
+
return false;
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
return month >= 1 && month <= 12;
|
|
317
392
|
};
|
|
318
393
|
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
IS_ROUTING_NUMBER_ERROR
|
|
325
|
-
);
|
|
326
|
-
validatorFns[IS_ROUTING_NUMBER] = (value, args, form) => {
|
|
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) {
|
|
327
399
|
if (value === "") {
|
|
328
400
|
return true;
|
|
329
401
|
}
|
|
402
|
+
|
|
403
|
+
return new RegExp(args[0]).test(value); // new RexExp never throws an error, no matter the input
|
|
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);
|
|
410
|
+
|
|
411
|
+
validatorFns[IS_ROUTING_NUMBER] = function (value, args, form) {
|
|
412
|
+
if (value === "") {
|
|
413
|
+
return true;
|
|
414
|
+
}
|
|
415
|
+
|
|
330
416
|
if (value.length != 9) {
|
|
331
417
|
return false;
|
|
332
418
|
}
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
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);
|
|
346
434
|
return sum != 0 && sum % 10 == 0;
|
|
347
435
|
};
|
|
348
436
|
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
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) {
|
|
353
442
|
if (value === "") {
|
|
354
443
|
return true;
|
|
355
444
|
}
|
|
445
|
+
|
|
356
446
|
return new RegExp(/[0-9]/).test(value);
|
|
357
447
|
};
|
|
358
448
|
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
);
|
|
365
|
-
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) {
|
|
366
454
|
if (value === "") {
|
|
367
455
|
return true;
|
|
368
456
|
}
|
|
457
|
+
|
|
369
458
|
return new RegExp(/[a-z]/).test(value);
|
|
370
459
|
};
|
|
371
460
|
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
);
|
|
378
|
-
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) {
|
|
379
466
|
if (value === "") {
|
|
380
467
|
return true;
|
|
381
468
|
}
|
|
469
|
+
|
|
382
470
|
return new RegExp(/[A-Z]/).test(value);
|
|
383
471
|
};
|
|
384
472
|
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
);
|
|
391
|
-
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) {
|
|
392
478
|
if (value === "") {
|
|
393
479
|
return true;
|
|
394
480
|
}
|
|
481
|
+
|
|
395
482
|
return new RegExp(/[!@#$%^&*.?]/).test(value);
|
|
396
483
|
};
|
|
397
484
|
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
);
|
|
404
|
-
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) {
|
|
405
490
|
if (value === "") {
|
|
406
491
|
return true;
|
|
407
492
|
}
|
|
493
|
+
|
|
408
494
|
return new RegExp(/^\S+@\S+\.\S+$/).test(value);
|
|
409
495
|
};
|
|
410
496
|
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
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];
|
|
417
502
|
|
|
418
|
-
const runValidator = (validator, value, form) => {
|
|
419
|
-
const validatorFn = validatorFns[validator.type];
|
|
420
503
|
if (validatorFn === undefined) {
|
|
421
504
|
throw new Error(runValidatorErrorMessage(validator.type));
|
|
422
505
|
}
|
|
506
|
+
|
|
423
507
|
return validatorFn(value, validator.args, form) ? null : validator.error;
|
|
424
508
|
};
|
|
425
509
|
|
|
426
|
-
|
|
427
|
-
return validators
|
|
428
|
-
|
|
429
|
-
|
|
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
|
+
});
|
|
430
516
|
};
|
|
431
517
|
|
|
432
|
-
|
|
433
|
-
|
|
518
|
+
var computeConstraints = function computeConstraints(fieldName, form) {
|
|
519
|
+
var constraints = form[fieldName].constraints;
|
|
434
520
|
return _computeErrors(fieldName, form, constraints);
|
|
435
521
|
};
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
const validators = form[fieldName].validators;
|
|
522
|
+
var computeErrors = function computeErrors(fieldName, form) {
|
|
523
|
+
var validators = form[fieldName].validators;
|
|
439
524
|
return _computeErrors(fieldName, form, validators);
|
|
440
525
|
};
|
|
441
526
|
|
|
@@ -1189,7 +1274,7 @@ var Immer = function Immer(config) {
|
|
|
1189
1274
|
};
|
|
1190
1275
|
|
|
1191
1276
|
Immer.prototype.produce = function produce (base, recipe, patchListener) {
|
|
1192
|
-
var this$1 = this;
|
|
1277
|
+
var this$1$1 = this;
|
|
1193
1278
|
|
|
1194
1279
|
// curried invocation
|
|
1195
1280
|
if (typeof base === "function" && typeof recipe !== "function") {
|
|
@@ -1197,12 +1282,12 @@ Immer.prototype.produce = function produce (base, recipe, patchListener) {
|
|
|
1197
1282
|
recipe = base;
|
|
1198
1283
|
var self = this;
|
|
1199
1284
|
return function curriedProduce(base) {
|
|
1200
|
-
var this$1 = this;
|
|
1285
|
+
var this$1$1 = this;
|
|
1201
1286
|
if ( base === void 0 ) base = defaultBase;
|
|
1202
1287
|
var args = [], len = arguments.length - 1;
|
|
1203
1288
|
while ( len-- > 0 ) args[ len ] = arguments[ len + 1 ];
|
|
1204
1289
|
|
|
1205
|
-
return self.produce(base, function (draft) { return recipe.call.apply(recipe, [ this$1, draft ].concat( args )); }); // prettier-ignore
|
|
1290
|
+
return self.produce(base, function (draft) { return recipe.call.apply(recipe, [ this$1$1, draft ].concat( args )); }); // prettier-ignore
|
|
1206
1291
|
};
|
|
1207
1292
|
} // prettier-ignore
|
|
1208
1293
|
|
|
@@ -1234,7 +1319,7 @@ Immer.prototype.produce = function produce (base, recipe, patchListener) {
|
|
|
1234
1319
|
if (result instanceof Promise) {
|
|
1235
1320
|
return result.then(function (result) {
|
|
1236
1321
|
scope.usePatches(patchListener);
|
|
1237
|
-
return this$1.processResult(result, scope);
|
|
1322
|
+
return this$1$1.processResult(result, scope);
|
|
1238
1323
|
}, function (error) {
|
|
1239
1324
|
scope.revoke();
|
|
1240
1325
|
throw error;
|
|
@@ -1251,14 +1336,14 @@ Immer.prototype.produce = function produce (base, recipe, patchListener) {
|
|
|
1251
1336
|
};
|
|
1252
1337
|
|
|
1253
1338
|
Immer.prototype.produceWithPatches = function produceWithPatches (arg1, arg2, arg3) {
|
|
1254
|
-
var this$1 = this;
|
|
1339
|
+
var this$1$1 = this;
|
|
1255
1340
|
|
|
1256
1341
|
if (typeof arg1 === "function") {
|
|
1257
1342
|
return function (state) {
|
|
1258
1343
|
var args = [], len = arguments.length - 1;
|
|
1259
1344
|
while ( len-- > 0 ) args[ len ] = arguments[ len + 1 ];
|
|
1260
1345
|
|
|
1261
|
-
return this$1.produceWithPatches(state, function (draft) { return arg1.apply(void 0, [ draft ].concat( args )); });
|
|
1346
|
+
return this$1$1.produceWithPatches(state, function (draft) { return arg1.apply(void 0, [ draft ].concat( args )); });
|
|
1262
1347
|
};
|
|
1263
1348
|
} // non-curried form
|
|
1264
1349
|
|
|
@@ -1383,7 +1468,7 @@ Immer.prototype.processResult = function processResult (result, scope) {
|
|
|
1383
1468
|
|
|
1384
1469
|
|
|
1385
1470
|
Immer.prototype.finalize = function finalize (draft, path, scope) {
|
|
1386
|
-
var this$1 = this;
|
|
1471
|
+
var this$1$1 = this;
|
|
1387
1472
|
|
|
1388
1473
|
var state = draft[DRAFT_STATE];
|
|
1389
1474
|
|
|
@@ -1417,7 +1502,7 @@ Immer.prototype.finalize = function finalize (draft, path, scope) {
|
|
|
1417
1502
|
var base = state.base;
|
|
1418
1503
|
var copy = state.copy;
|
|
1419
1504
|
each(base, function (prop) {
|
|
1420
|
-
if (!has(copy, prop)) { this$1.onDelete(state, prop); }
|
|
1505
|
+
if (!has(copy, prop)) { this$1$1.onDelete(state, prop); }
|
|
1421
1506
|
});
|
|
1422
1507
|
}
|
|
1423
1508
|
}
|
|
@@ -1446,7 +1531,7 @@ Immer.prototype.finalize = function finalize (draft, path, scope) {
|
|
|
1446
1531
|
|
|
1447
1532
|
|
|
1448
1533
|
Immer.prototype.finalizeTree = function finalizeTree (root, rootPath, scope) {
|
|
1449
|
-
var this$1 = this;
|
|
1534
|
+
var this$1$1 = this;
|
|
1450
1535
|
|
|
1451
1536
|
var state = root[DRAFT_STATE];
|
|
1452
1537
|
|
|
@@ -1472,7 +1557,7 @@ Immer.prototype.finalizeTree = function finalizeTree (root, rootPath, scope) {
|
|
|
1472
1557
|
if (isDraft(value)) {
|
|
1473
1558
|
var path = isDraftProp && needPatches && !state.assigned[prop] ? rootPath.concat(prop) : null; // Drafts owned by `scope` are finalized here.
|
|
1474
1559
|
|
|
1475
|
-
value = this$1.finalize(value, path, scope); // Drafts from another scope must prevent auto-freezing.
|
|
1560
|
+
value = this$1$1.finalize(value, path, scope); // Drafts from another scope must prevent auto-freezing.
|
|
1476
1561
|
|
|
1477
1562
|
if (isDraft(value)) {
|
|
1478
1563
|
scope.canAutoFreeze = false;
|
|
@@ -1497,8 +1582,8 @@ Immer.prototype.finalizeTree = function finalizeTree (root, rootPath, scope) {
|
|
|
1497
1582
|
each(value, finalizeProperty);
|
|
1498
1583
|
}
|
|
1499
1584
|
|
|
1500
|
-
if (isDraftProp && this$1.onAssign) {
|
|
1501
|
-
this$1.onAssign(state, prop, value);
|
|
1585
|
+
if (isDraftProp && this$1$1.onAssign) {
|
|
1586
|
+
this$1$1.onAssign(state, prop, value);
|
|
1502
1587
|
}
|
|
1503
1588
|
};
|
|
1504
1589
|
|
|
@@ -1533,14 +1618,14 @@ var produce = immer.produce;
|
|
|
1533
1618
|
* [nextState, patches, inversePatches] (instead of just the next state)
|
|
1534
1619
|
*/
|
|
1535
1620
|
|
|
1536
|
-
|
|
1621
|
+
immer.produceWithPatches.bind(immer);
|
|
1537
1622
|
/**
|
|
1538
1623
|
* Pass true to automatically freeze all copies created by Immer.
|
|
1539
1624
|
*
|
|
1540
1625
|
* By default, auto-freezing is disabled in production.
|
|
1541
1626
|
*/
|
|
1542
1627
|
|
|
1543
|
-
|
|
1628
|
+
immer.setAutoFreeze.bind(immer);
|
|
1544
1629
|
/**
|
|
1545
1630
|
* Pass true to use the ES2015 `Proxy` class when creating drafts, which is
|
|
1546
1631
|
* always faster than using ES5 proxies.
|
|
@@ -1548,20 +1633,20 @@ var setAutoFreeze = immer.setAutoFreeze.bind(immer);
|
|
|
1548
1633
|
* By default, feature detection is used, so calling this is rarely necessary.
|
|
1549
1634
|
*/
|
|
1550
1635
|
|
|
1551
|
-
|
|
1636
|
+
immer.setUseProxies.bind(immer);
|
|
1552
1637
|
/**
|
|
1553
1638
|
* Apply an array of Immer patches to the first argument.
|
|
1554
1639
|
*
|
|
1555
1640
|
* This function is a producer, which means copy-on-write is in effect.
|
|
1556
1641
|
*/
|
|
1557
1642
|
|
|
1558
|
-
|
|
1643
|
+
immer.applyPatches.bind(immer);
|
|
1559
1644
|
/**
|
|
1560
1645
|
* Create an Immer draft from the given base state, which may be a draft itself.
|
|
1561
1646
|
* The draft can be modified until you finalize it with the `finishDraft` function.
|
|
1562
1647
|
*/
|
|
1563
1648
|
|
|
1564
|
-
|
|
1649
|
+
immer.createDraft.bind(immer);
|
|
1565
1650
|
/**
|
|
1566
1651
|
* Finalize an Immer draft from a `createDraft` call, returning the base state
|
|
1567
1652
|
* (if no changes were made) or a modified copy. The draft must *not* be
|
|
@@ -1571,129 +1656,181 @@ var createDraft = immer.createDraft.bind(immer);
|
|
|
1571
1656
|
* changes that were made.
|
|
1572
1657
|
*/
|
|
1573
1658
|
|
|
1574
|
-
|
|
1659
|
+
immer.finishDraft.bind(immer);
|
|
1660
|
+
|
|
1661
|
+
var createInitialState = function createInitialState(formConfig) {
|
|
1662
|
+
var initialForm = {};
|
|
1663
|
+
var formConfigKeys = Object.keys(formConfig);
|
|
1575
1664
|
|
|
1576
|
-
|
|
1577
|
-
|
|
1578
|
-
const formConfigKeys = Object.keys(formConfig);
|
|
1579
|
-
for (let formKey of formConfigKeys) {
|
|
1665
|
+
for (var _i = 0, _formConfigKeys = formConfigKeys; _i < _formConfigKeys.length; _i++) {
|
|
1666
|
+
var formKey = _formConfigKeys[_i];
|
|
1580
1667
|
initialForm[formKey] = {
|
|
1581
1668
|
dirty: false,
|
|
1582
1669
|
rawValue: formConfig[formKey].defaultValue || "",
|
|
1583
1670
|
validators: formConfig[formKey].validators || [],
|
|
1584
1671
|
constraints: formConfig[formKey].constraints || []
|
|
1585
1672
|
};
|
|
1586
|
-
}
|
|
1587
|
-
// Because validators require the entire form we have to do a
|
|
1673
|
+
} // Because validators require the entire form we have to do a
|
|
1588
1674
|
// second pass to add errors once the initial form has been
|
|
1589
1675
|
// constructed
|
|
1590
|
-
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
|
|
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;
|
|
1594
1683
|
}
|
|
1684
|
+
|
|
1595
1685
|
return initialForm;
|
|
1596
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";
|
|
1597
1701
|
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
}
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
|
|
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
|
+
}
|
|
1606
1725
|
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
|
|
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
|
+
});
|
|
1612
1753
|
|
|
1613
|
-
|
|
1614
|
-
|
|
1615
|
-
|
|
1616
|
-
|
|
1617
|
-
|
|
1618
|
-
|
|
1619
|
-
|
|
1620
|
-
|
|
1621
|
-
|
|
1622
|
-
|
|
1623
|
-
|
|
1624
|
-
|
|
1625
|
-
|
|
1626
|
-
|
|
1627
|
-
|
|
1628
|
-
|
|
1629
|
-
|
|
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
|
+
});
|
|
1630
1775
|
|
|
1631
|
-
|
|
1632
|
-
|
|
1633
|
-
|
|
1634
|
-
|
|
1635
|
-
let errors = computeErrors(fieldName, draftState);
|
|
1636
|
-
let dirty = fieldName === changedFieldName ? true : field.dirty;
|
|
1637
|
-
draftState[fieldName].errors = errors;
|
|
1638
|
-
draftState[fieldName].dirty = dirty;
|
|
1639
|
-
draftState[fieldName].hasErrors = errors.length > 0;
|
|
1640
|
-
}
|
|
1641
|
-
});
|
|
1642
|
-
case CLEAR:
|
|
1643
|
-
return createInitialState(formConfig);
|
|
1644
|
-
case ADD_VALIDATOR:
|
|
1645
|
-
const fieldWithOverride = action.payload.fieldName;
|
|
1646
|
-
const newValidator = action.payload.validator;
|
|
1647
|
-
|
|
1648
|
-
return produce(state, draftState => {
|
|
1649
|
-
draftState[fieldWithOverride].validators.push(newValidator);
|
|
1650
|
-
const fields = Object.entries(draftState);
|
|
1651
|
-
for (let entry of fields) {
|
|
1652
|
-
let fieldName = entry[0];
|
|
1653
|
-
let field = entry[1];
|
|
1654
|
-
let errors = computeErrors(fieldName, draftState);
|
|
1655
|
-
let dirty = field.dirty;
|
|
1656
|
-
draftState[fieldName].errors = errors;
|
|
1657
|
-
draftState[fieldName].dirty = dirty;
|
|
1658
|
-
draftState[fieldName].hasErrors = errors.length > 0;
|
|
1659
|
-
}
|
|
1660
|
-
});
|
|
1661
|
-
default:
|
|
1662
|
-
return state;
|
|
1663
|
-
}
|
|
1776
|
+
default:
|
|
1777
|
+
return state;
|
|
1778
|
+
}
|
|
1779
|
+
};
|
|
1664
1780
|
};
|
|
1665
|
-
|
|
1666
|
-
const createMapDispatchToProps = formConfig => {
|
|
1781
|
+
var createMapDispatchToProps = function createMapDispatchToProps(formConfig) {
|
|
1667
1782
|
// Do memo-ization
|
|
1668
|
-
|
|
1669
|
-
|
|
1670
|
-
return dispatch
|
|
1783
|
+
var cachedDispatch;
|
|
1784
|
+
var cacheValue;
|
|
1785
|
+
return function (dispatch) {
|
|
1671
1786
|
if (dispatch == cachedDispatch) {
|
|
1672
1787
|
return cacheValue;
|
|
1673
1788
|
}
|
|
1674
|
-
|
|
1789
|
+
|
|
1790
|
+
var dispatchObj = {};
|
|
1675
1791
|
dispatchObj.fields = {};
|
|
1676
|
-
|
|
1677
|
-
|
|
1792
|
+
var keys = Object.keys(formConfig);
|
|
1793
|
+
|
|
1794
|
+
var _loop = function _loop() {
|
|
1795
|
+
var fieldName = _keys[_i5];
|
|
1678
1796
|
dispatchObj.fields[fieldName] = {
|
|
1679
|
-
set:
|
|
1680
|
-
|
|
1797
|
+
set: function set(value) {
|
|
1798
|
+
return dispatch(_set(fieldName)(value));
|
|
1799
|
+
},
|
|
1800
|
+
addValidator: function addValidator(validator) {
|
|
1801
|
+
return dispatch(_addValidator(fieldName)(validator));
|
|
1802
|
+
}
|
|
1681
1803
|
};
|
|
1804
|
+
};
|
|
1805
|
+
|
|
1806
|
+
for (var _i5 = 0, _keys = keys; _i5 < _keys.length; _i5++) {
|
|
1807
|
+
_loop();
|
|
1682
1808
|
}
|
|
1683
|
-
|
|
1809
|
+
|
|
1810
|
+
dispatchObj.form = {
|
|
1811
|
+
clear: function clear() {
|
|
1812
|
+
return dispatch(_clear());
|
|
1813
|
+
}
|
|
1814
|
+
};
|
|
1684
1815
|
cachedDispatch = dispatch;
|
|
1685
|
-
cacheValue = {
|
|
1816
|
+
cacheValue = {
|
|
1817
|
+
actions: dispatchObj
|
|
1818
|
+
};
|
|
1686
1819
|
return cacheValue;
|
|
1687
1820
|
};
|
|
1688
1821
|
};
|
|
1689
|
-
|
|
1690
|
-
|
|
1691
|
-
|
|
1692
|
-
|
|
1693
|
-
|
|
1694
|
-
|
|
1695
|
-
|
|
1696
|
-
|
|
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
|
+
};
|
|
1697
1834
|
|
|
1698
1835
|
exports.createFormState = createFormState;
|
|
1699
1836
|
exports.dateAfterToday = dateAfterToday;
|
|
@@ -1705,6 +1842,7 @@ exports.hasSpecialCharacter = hasSpecialCharacter;
|
|
|
1705
1842
|
exports.hasUppercaseLetter = hasUppercaseLetter;
|
|
1706
1843
|
exports.isProbablyEmail = isProbablyEmail;
|
|
1707
1844
|
exports.isRoutingNumber = isRoutingNumber;
|
|
1845
|
+
exports.isValidMonth = isValidMonth;
|
|
1708
1846
|
exports.matchesField = matchesField;
|
|
1709
1847
|
exports.matchesRegex = matchesRegex;
|
|
1710
1848
|
exports.numberGreaterThan = numberGreaterThan;
|