Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

react-form-with-constraints

Package Overview
Dependencies
Maintainers
1
Versions
77
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-form-with-constraints - npm Package Compare versions

Comparing version 0.15.0 to 0.15.1

6

CHANGELOG.md

@@ -0,1 +1,7 @@

## v0.15.1 (2020/10/15)
### Fixes
- Set field.element as soon as possible
## v0.15.0 (2020/03/05)

@@ -2,0 +8,0 @@

9

dist/react-form-with-constraints.development.js

@@ -466,9 +466,7 @@ (function (global, factory) {

input = inputs[i];
return [4, this.validateField(forceValidateFields, new InputElement(input))];
return [4, this.validateField(forceValidateFields, new InputElement(input), input)];
case 2:
field = _a.sent();
if (field !== undefined) {
field.element = input;
if (field !== undefined)
fields.push(field);
}
_a.label = 3;

@@ -483,3 +481,3 @@ case 3:

};
FormWithConstraints.prototype.validateField = function (forceValidateFields, input) {
FormWithConstraints.prototype.validateField = function (forceValidateFields, input, nativeInput) {
return __awaiter(this, void 0, void 0, function () {

@@ -496,2 +494,3 @@ var fieldName, field, arrayOfArrays;

if (!(forceValidateFields || !field.hasFeedbacks())) return [3, 3];
field.element = nativeInput;
field.clearValidations();

@@ -498,0 +497,0 @@ this.emitFieldWillValidateEvent(fieldName);

@@ -1,2 +0,2 @@

!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("react"),require("prop-types")):"function"==typeof define&&define.amd?define(["exports","react","prop-types"],t):t((e=e||self).ReactFormWithConstraints={},e.React,e.PropTypes)}(this,function(u,p,e){"use strict";var n=function(e,t){return(n=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var i in t)t.hasOwnProperty(i)&&(e[i]=t[i])})(e,t)};function r(e,t){function i(){this.constructor=e}n(e,t),e.prototype=null===t?Object.create(t):(i.prototype=t.prototype,new i)}var h=function(){return(h=Object.assign||function(e){for(var t,i=1,n=arguments.length;i<n;i++)for(var r in t=arguments[i])Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r]);return e}).apply(this,arguments)};function v(e,t){var i={};for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&t.indexOf(n)<0&&(i[n]=e[n]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var r=0;for(n=Object.getOwnPropertySymbols(e);r<n.length;r++)t.indexOf(n[r])<0&&Object.prototype.propertyIsEnumerable.call(e,n[r])&&(i[n[r]]=e[n[r]])}return i}function l(a,s,o,l){return new(o=o||Promise)(function(e,t){function i(e){try{r(l.next(e))}catch(e){t(e)}}function n(e){try{r(l.throw(e))}catch(e){t(e)}}function r(t){t.done?e(t.value):new o(function(e){e(t.value)}).then(i,n)}r((l=l.apply(a,s||[])).next())})}function d(i,n){var r,a,s,e,o={label:0,sent:function(){if(1&s[0])throw s[1];return s[1]},trys:[],ops:[]};return e={next:t(0),throw:t(1),return:t(2)},"function"==typeof Symbol&&(e[Symbol.iterator]=function(){return this}),e;function t(t){return function(e){return function(t){if(r)throw new TypeError("Generator is already executing.");for(;o;)try{if(r=1,a&&(s=2&t[0]?a.return:t[0]?a.throw||((s=a.return)&&s.call(a),0):a.next)&&!(s=s.call(a,t[1])).done)return s;switch(a=0,s&&(t=[2&t[0],s.value]),t[0]){case 0:case 1:s=t;break;case 4:return o.label++,{value:t[1],done:!1};case 5:o.label++,a=t[1],t=[0];continue;case 7:t=o.ops.pop(),o.trys.pop();continue;default:if(!(s=0<(s=o.trys).length&&s[s.length-1])&&(6===t[0]||2===t[0])){o=0;continue}if(3===t[0]&&(!s||t[1]>s[0]&&t[1]<s[3])){o.label=t[1];break}if(6===t[0]&&o.label<s[1]){o.label=s[1],s=t;break}if(s&&o.label<s[2]){o.label=s[2],o.ops.push(t);break}s[2]&&o.ops.pop(),o.trys.pop();continue}t=n.call(i,o)}catch(e){t=[6,e],a=0}finally{r=s=0}if(5&t[0])throw t[1];return{value:t[0]?t[1]:void 0,done:!0}}([t,e])}}}function i(){for(var e=0,t=0,i=arguments.length;t<i;t++)e+=arguments[t].length;var n=Array(e),r=0;for(t=0;t<i;t++)for(var a=arguments[t],s=0,o=a.length;s<o;s++,r++)n[r]=a[s];return n}var a=(t.prototype.emitSync=function(e){for(var t=[],i=1;i<arguments.length;i++)t[i-1]=arguments[i];var n=this.getListeners(e),r=new Array;return n.forEach(function(e){return r.push(e.apply(void 0,t))}),r},t.prototype.emitAsync=function(s){for(var o=[],e=1;e<arguments.length;e++)o[e-1]=arguments[e];return l(this,void 0,void 0,function(){var t,i,n,r,a;return d(this,function(e){switch(e.label){case 0:t=this.getListeners(s),i=new Array,n=0,e.label=1;case 1:return n<t.length?(a=(r=i).push,[4,t[n].apply(t,o)]):[3,4];case 2:a.apply(r,[e.sent()]),e.label=3;case 3:return n++,[3,1];case 4:return[2,i]}})})},t.prototype.getListeners=function(e){var t=this.listeners.get(e);return void 0!==t?(console.assert(0<t.length,"No listener for event '"+e+"'"),t):[]},t.prototype.addListener=function(e,t){this.listeners.has(e)||this.listeners.set(e,[]);var i=this.listeners.get(e);console.assert(-1===i.indexOf(t),"Listener already added for event '"+e+"'"),i.push(t)},t.prototype.removeListener=function(e,t){var i=this.listeners.get(e);console.assert(void 0!==i,"Unknown event '"+e+"'");var n=i.lastIndexOf(t);console.assert(-1<n,"Listener not found for event '"+e+"'"),i.splice(n,1),0===i.length&&this.listeners.delete(e)},t);function t(){this.listeners=new Map}var s="VALIDATE_FIELD_EVENT";function o(e){return r(t,i=e),t.prototype.emitValidateFieldEvent=function(e){return this.validateFieldEventEmitter.emitAsync(s,e)},t.prototype.addValidateFieldEventListener=function(e){this.validateFieldEventEmitter.addListener(s,e)},t.prototype.removeValidateFieldEventListener=function(e){this.validateFieldEventEmitter.removeListener(s,e)},t;function t(){var e=null!==i&&i.apply(this,arguments)||this;return e.validateFieldEventEmitter=new a,e}var i}var c="FIELD_WILL_VALIDATE_EVENT";function f(e){return r(t,i=e),t.prototype.emitFieldWillValidateEvent=function(e){return this.fieldWillValidateEventEmitter.emitSync(c,e)},t.prototype.addFieldWillValidateEventListener=function(e){this.fieldWillValidateEventEmitter.addListener(c,e)},t.prototype.removeFieldWillValidateEventListener=function(e){this.fieldWillValidateEventEmitter.removeListener(c,e)},t;function t(){var e=null!==i&&i.apply(this,arguments)||this;return e.fieldWillValidateEventEmitter=new a,e}var i}var y="FIELD_DID_VALIDATE_EVENT";function m(e){return r(t,i=e),t.prototype.emitFieldDidValidateEvent=function(e){return this.fieldDidValidateEventEmitter.emitSync(y,e)},t.prototype.addFieldDidValidateEventListener=function(e){this.fieldDidValidateEventEmitter.addListener(y,e)},t.prototype.removeFieldDidValidateEventListener=function(e){this.fieldDidValidateEventEmitter.removeListener(y,e)},t;function t(){var e=null!==i&&i.apply(this,arguments)||this;return e.fieldDidValidateEventEmitter=new a,e}var i}var F="FIELD_DID_RESET_EVENT";function E(e){return r(t,i=e),t.prototype.emitFieldDidResetEvent=function(e){return this.fieldDidResetEventEmitter.emitSync(F,e)},t.prototype.addFieldDidResetEventListener=function(e){this.fieldDidResetEventEmitter.addListener(F,e)},t.prototype.removeFieldDidResetEventListener=function(e){this.fieldDidResetEventEmitter.removeListener(F,e)},t;function t(){var e=null!==i&&i.apply(this,arguments)||this;return e.fieldDidResetEventEmitter=new a,e}var i}var b=function(e){this.badInput=e.badInput,this.customError=e.customError,this.patternMismatch=e.patternMismatch,this.rangeOverflow=e.rangeOverflow,this.rangeUnderflow=e.rangeUnderflow,this.stepMismatch=e.stepMismatch,this.tooLong=e.tooLong,this.tooShort=e.tooShort,this.typeMismatch=e.typeMismatch,this.valid=e.valid,this.valueMissing=e.valueMissing};function g(e){return void 0===e.props}var k,w=function(e){g(e)?(e=e,this.name=e.name,this.type=e.type,this.value=e.value,this.validity=new b(e.validity),this.validationMessage=e.validationMessage):(e=e,this.name=e.props.name,this.type=void 0,this.value=e.props.value,this.validity=void 0,this.validationMessage=void 0)};(k=u.FieldFeedbackType||(u.FieldFeedbackType={})).Error="error",k.Warning="warning",k.Info="info",k.WhenValid="whenValid";var V,D=(L.prototype.addOrReplaceValidation=function(t){var e=this.validations.findIndex(function(e){return e.key===t.key});-1<e?this.validations[e]=t:this.validations.push(t)},L.prototype.clearValidations=function(){!function(e){for(;e.length;)e.pop()}(this.validations)},L.prototype.hasFeedbacksOfType=function(t,i){return this.validations.some(function(e){return(void 0===i||e.key.startsWith(i+"."))&&e.type===t&&!0===e.show})},L.prototype.hasErrors=function(e){return this.hasFeedbacksOfType(u.FieldFeedbackType.Error,e)},L.prototype.hasWarnings=function(e){return this.hasFeedbacksOfType(u.FieldFeedbackType.Warning,e)},L.prototype.hasInfos=function(e){return this.hasFeedbacksOfType(u.FieldFeedbackType.Info,e)},L.prototype.hasFeedbacks=function(e){return this.hasErrors(e)||this.hasWarnings(e)||this.hasInfos(e)},L.prototype.isValid=function(){return!this.hasErrors()},L);function L(e){this.name=e,this.validations=[]}(V=u.FieldEvent||(u.FieldEvent={})).Added="FIELD_ADDED",V.Removed="FIELD_REMOVED";var S,x=(r(R,S=a),R.prototype.getField=function(t){var e=this.fields.filter(function(e){return e.name===t});return 1===e.length?e[0]:void 0},R.prototype.addField=function(t){var e=this.fields.filter(function(e){return e.name===t});if(console.assert(0===e.length||1===e.length,"Cannot have more than 1 field matching '"+t+"'"),0===e.length){var i=new D(t);this.fields.push(i),this.emitSync(u.FieldEvent.Added,i)}},R.prototype.removeField=function(t){var e=this.fields.filter(function(e){return e.name===t}),i=this.fields.indexOf(e[0]);-1<i&&(this.fields.splice(i,1),this.emitSync(u.FieldEvent.Removed,t))},R.prototype.isValid=function(){return this.fields.every(function(e){return e.isValid()})},R.prototype.hasFeedbacks=function(){return this.fields.some(function(e){return e.hasFeedbacks()})},R);function R(){var e=null!==S&&S.apply(this,arguments)||this;return e.fields=new Array,e}function O(e){return e.reduce(function(e,t){return e.concat(Array.isArray(t)?O(t):t)},[])}function W(e){return void 0!==e}var I,M=(r(T,I=p.PureComponent),T);function T(){return null!==I&&I.apply(this,arguments)||this}var N,_=(r(A,N=E(f(m(o(M))))),A.prototype.getChildContext=function(){return{form:this}},A.prototype.computeFieldFeedbacksKey=function(){return""+this.fieldFeedbacksKeyCounter++},A.prototype.validateFields=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return this._validateFields.apply(this,i([!0],e))},A.prototype.validateForm=function(){return this.validateFieldsWithoutFeedback()},A.prototype.validateFieldsWithoutFeedback=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return this._validateFields.apply(this,i([!1],e))},A.prototype._validateFields=function(s){for(var o=[],e=1;e<arguments.length;e++)o[e-1]=arguments[e];return l(this,void 0,void 0,function(){var t,i,n,r,a;return d(this,function(e){switch(e.label){case 0:t=new Array,i=this.normalizeInputs.apply(this,o),n=0,e.label=1;case 1:return n<i.length?(r=i[n],[4,this.validateField(s,new w(r))]):[3,4];case 2:void 0!==(a=e.sent())&&(a.element=r,t.push(a)),e.label=3;case 3:return n++,[3,1];case 4:return[2,t]}})})},A.prototype.validateField=function(r,a){return l(this,void 0,void 0,function(){var t,i,n;return d(this,function(e){switch(e.label){case 0:return t=a.name,void 0!==(i=this.fieldsStore.getField(t))?[3,1]:[3,3];case 1:return!r&&i.hasFeedbacks()?[3,3]:(i.clearValidations(),this.emitFieldWillValidateEvent(t),[4,this.emitValidateFieldEvent(a)]);case 2:n=e.sent(),console.assert(JSON.stringify(O(n).filter(W))===JSON.stringify(i.validations),"FieldsStore does not match emitValidateFieldEvent() result, did the user changed the input rapidly?"),this.emitFieldDidValidateEvent(i),e.label=3;case 3:return[2,i]}})})},A.prototype.normalizeInputs=function(){for(var e,r=this,t=[],i=0;i<arguments.length;i++)t[i]=arguments[i];return 0===t.length?(e=(e=Array.from(this.form.querySelectorAll("[name]"))).filter(function(e){return void 0!==e.validity})).filter(function(e){return"checkbox"!==e.type&&"radio"!==e.type}).map(function(e){return e.name}).forEach(function(e,t,i){if(i.indexOf(e)!==t)throw new Error("Multiple elements matching '[name=\""+e+"\"]' inside the form")}):e=t.map(function(e){if("string"!=typeof e)return e;var t='[name="'+e+'"]',i=Array.from(r.form.querySelectorAll(t));if(0<i.filter(function(e){return void 0===e.validity}).length)throw new Error("'"+t+"' should match an <input>, <select> or <textarea>");if(1<i.filter(function(e){return"checkbox"!==e.type&&"radio"!==e.type}).length)throw new Error("Multiple elements matching '"+t+"' inside the form");var n=i[0];if(void 0===n)throw new Error("Could not find field '"+t+"' inside the form");return n}),e},A.prototype.isValid=function(){return this.fieldsStore.isValid()},A.prototype.hasFeedbacks=function(){return this.fieldsStore.hasFeedbacks()},A.prototype.reset=function(){return this.resetFields()},A.prototype.resetFields=function(){for(var i=this,e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];var n=new Array;return this.normalizeInputs.apply(this,e).forEach(function(e){var t=i.resetField(new w(e));void 0!==t&&n.push(t)}),n},A.prototype.resetField=function(e){var t=e.name,i=this.fieldsStore.getField(t);return void 0===i||(i.clearValidations(),this.emitFieldDidResetEvent(i)),i},A.prototype.render=function(){var t=this;return p.createElement("form",h({ref:function(e){return t.form=e}},this.props))},A.childContextTypes={form:e.instanceOf(A).isRequired},A);function A(){var e=null!==N&&N.apply(this,arguments)||this;return e.form=null,e.fieldsStore=new x,e.fieldFeedbacksKeyCounter=0,e}var C,P=(r(j,C=p.PureComponent),j);function j(){return null!==C&&C.apply(this,arguments)||this}var q,U,K=(r(z,q=o(P)),z.prototype.getChildContext=function(){return{fieldFeedbacks:this}},z.prototype.computeFieldFeedbackKey=function(){return this.key+"."+this.fieldFeedbackKeyCounter++},z.prototype.addFieldFeedback=function(){return this.computeFieldFeedbackKey()},z.prototype.componentDidMount=function(){var e=this.context,t=e.form,i=e.fieldFeedbacks;t.fieldsStore.addField(this.fieldName),(i||t).addValidateFieldEventListener(this.validate)},z.prototype.componentWillUnmount=function(){var e=this.context,t=e.form,i=e.fieldFeedbacks;t.fieldsStore.removeField(this.fieldName),(i||t).removeValidateFieldEventListener(this.validate)},z.prototype._validate=function(t){return l(this,void 0,void 0,function(){return d(this,function(e){switch(e.label){case 0:return[4,this.emitValidateFieldEvent(t)];case 1:return[2,O(e.sent())]}})})},z.prototype.render=function(){var e=this.props.children;return void 0!==e?e:null},z.defaultProps={stop:"first-error"},z.contextTypes={form:e.instanceOf(_).isRequired,fieldFeedbacks:e.instanceOf(z)},z.childContextTypes={fieldFeedbacks:e.instanceOf(z).isRequired},z);function z(e,t){var i=q.call(this,e,t)||this;i.fieldFeedbackKeyCounter=0,i.validate=function(s){return l(i,void 0,void 0,function(){var t,i,n,r,a;return d(this,function(e){switch(e.label){case 0:return(t=this.context,i=t.form,n=t.fieldFeedbacks,s.name!==this.fieldName)?[3,3]:(a=i.fieldsStore.getField(this.fieldName),n&&("first"===n.props.stop&&a.hasFeedbacks(n.key)||"first-error"===n.props.stop&&a.hasErrors(n.key)||"first-warning"===n.props.stop&&a.hasWarnings(n.key)||"first-info"===n.props.stop&&a.hasInfos(n.key))?[3,3]:[3,1]);case 1:return[4,this._validate(s)];case 2:r=e.sent(),e.label=3;case 3:return[2,r]}})})};var n=t.form,r=t.fieldFeedbacks;if(i.key=r?r.computeFieldFeedbackKey():n.computeFieldFeedbacksKey(),r){if(i.fieldName=r.fieldName,void 0!==e.for)throw new Error("FieldFeedbacks cannot have a parent and a 'for' prop")}else{if(void 0===e.for)throw new Error("FieldFeedbacks cannot be without parent and without 'for' prop");i.fieldName=e.for}return i}(U=u.Status||(u.Status={}))[U.None=0]="None",U[U.Pending=1]="Pending",U[U.Rejected=2]="Rejected",U[U.Resolved=3]="Resolved";var J,G=(r(H,J=p.PureComponent),H);function H(){return null!==J&&J.apply(this,arguments)||this}var B,Q=(r(X,B=o(G)),X.prototype.getChildContext=function(){return{async:this}},X.prototype.componentDidMount=function(){this.context.fieldFeedbacks.addValidateFieldEventListener(this.validate)},X.prototype.componentWillUnmount=function(){this.context.fieldFeedbacks.removeValidateFieldEventListener(this.validate)},X.prototype._validate=function(n){return l(this,void 0,void 0,function(){var t,i;return d(this,function(e){switch(e.label){case 0:this.setState({status:u.Status.Pending}),e.label=1;case 1:return e.trys.push([1,3,,4]),[4,this.props.promise(n.value)];case 2:return t=e.sent(),this.setState({status:u.Status.Resolved,value:t}),[3,4];case 3:return i=e.sent(),this.setState({status:u.Status.Rejected,value:i}),[3,4];case 4:return[2,this.emitValidateFieldEvent(n)]}})})},X.prototype.render=function(){var e=this.props,t=this.state,i=null;switch(t.status){case u.Status.None:break;case u.Status.Pending:e.pending&&(i=e.pending);break;case u.Status.Resolved:e.then&&(i=e.then(t.value));break;case u.Status.Rejected:e.catch&&(i=e.catch(t.value));break;default:console.assert(!1,"Unknown status: '"+t.status+"'")}return i},X.contextTypes={form:e.instanceOf(_).isRequired,fieldFeedbacks:e.instanceOf(K).isRequired},X.childContextTypes={async:e.instanceOf(X).isRequired},X);function X(){var s=null!==B&&B.apply(this,arguments)||this;return s.state={status:u.Status.None},s.validate=function(e){var t,i=s.context,n=i.form,r=i.fieldFeedbacks,a=n.fieldsStore.getField(e.name);return"first"===r.props.stop&&a.hasFeedbacks(r.key)||"first-error"===r.props.stop&&a.hasErrors(r.key)||"first-warning"===r.props.stop&&a.hasWarnings(r.key)||"first-info"===r.props.stop&&a.hasInfos(r.key)?s.setState({status:u.Status.None}):t=s._validate(e),t},s}var Y,Z=(r($,Y=p.Component),$.prototype.componentDidMount=function(){this.context.form.addFieldWillValidateEventListener(this.fieldWillValidate),this.context.form.addFieldDidValidateEventListener(this.fieldDidValidate),this.context.form.addFieldDidResetEventListener(this.fieldDidReset)},$.prototype.componentWillUnmount=function(){this.context.form.removeFieldWillValidateEventListener(this.fieldWillValidate),this.context.form.removeFieldDidValidateEventListener(this.fieldDidValidate),this.context.form.removeFieldDidResetEventListener(this.fieldDidReset)},$.prototype.render=function(){var e=this.props,t=e.style,i=v(e,["style"]);return this.state.fieldIsValid?p.createElement("span",h({},i,{style:h({display:"block"},t)})):null},$.contextTypes={form:e.instanceOf(_).isRequired,fieldFeedbacks:e.instanceOf(K).isRequired},$);function $(){var t=null!==Y&&Y.apply(this,arguments)||this;return t.state={fieldIsValid:void 0},t.fieldWillValidate=function(e){e===t.context.fieldFeedbacks.fieldName&&t.setState({fieldIsValid:void 0})},t.fieldDidValidate=function(e){e.name===t.context.fieldFeedbacks.fieldName&&t.setState({fieldIsValid:e.isValid()})},t.fieldDidReset=function(e){e.name===t.context.fieldFeedbacks.fieldName&&t.setState({fieldIsValid:void 0})},t}var ee,te=(r(ie,ee=p.Component),ie.prototype.componentDidMount=function(){var e=this.context,t=e.form,i=e.fieldFeedbacks,n=e.async;n?n.addValidateFieldEventListener(this.validate):i.addValidateFieldEventListener(this.validate),t.addFieldDidResetEventListener(this.fieldDidReset)},ie.prototype.componentWillUnmount=function(){var e=this.context,t=e.form,i=e.fieldFeedbacks,n=e.async;n?n.removeValidateFieldEventListener(this.validate):i.removeValidateFieldEventListener(this.validate),t.removeFieldDidResetEventListener(this.fieldDidReset)},ie.prototype.render=function(){var e=this.props,t=(e.when,e.error,e.warning,e.info,e.className),i=e.classes,n=e.style,r=e.children,a=v(e,["when","error","warning","info","className","classes","style","children"]),s=this.state,o=s.validation,l=s.validationMessage,d=i[o.type],c=void 0!==t?t+" "+d:d;if(o.type===u.FieldFeedbackType.WhenValid)return p.createElement(Z,h({"data-feedback":this.key,style:n,className:c},a),r);if(o.show){var f=void 0!==r?r:l;return p.createElement("span",h({"data-feedback":this.key,className:c,style:h({display:"block"},n)},a),f)}return null},ie.defaultProps={when:function(){return!0},classes:{error:"error",warning:"warning",info:"info",whenValid:"when-valid"}},ie.contextTypes={form:e.instanceOf(_).isRequired,fieldFeedbacks:e.instanceOf(K).isRequired,async:e.instanceOf(Q)},ie);function ie(e,t){var l=ee.call(this,e,t)||this;l.validate=function(e){var t=l.props.when,i=l.context,n=i.form,r=i.fieldFeedbacks,a=n.fieldsStore.getField(e.name),s=h({},l.state.validation);if("first"===r.props.stop&&a.hasFeedbacks(r.key)||"first-error"===r.props.stop&&a.hasErrors(r.key)||"first-warning"===r.props.stop&&a.hasWarnings(r.key)||"first-info"===r.props.stop&&a.hasInfos(r.key))s.show=void 0;else if(s.show=!1,"function"==typeof t)s.show=t(e.value);else{if("string"!=typeof t)throw new TypeError("Invalid FieldFeedback 'when' type: "+typeof t);if("valid"===t)s.show=void 0;else{var o=e.validity;o.valid||("*"===t||o.badInput&&"badInput"===t||o.patternMismatch&&"patternMismatch"===t||o.rangeOverflow&&"rangeOverflow"===t||o.rangeUnderflow&&"rangeUnderflow"===t||o.stepMismatch&&"stepMismatch"===t||o.tooLong&&"tooLong"===t||o.tooShort&&"tooShort"===t||o.typeMismatch&&"typeMismatch"===t||o.valueMissing&&"valueMissing"===t)&&(s.show=!0)}}return a.addOrReplaceValidation(s),l.setState({validation:s,validationMessage:e.validationMessage}),s},l.fieldDidReset=function(e){e.name===l.context.fieldFeedbacks.fieldName&&l.setState(function(e){return{validation:h(h({},e.validation),{show:void 0}),validationMessage:""}})},l.key=t.fieldFeedbacks.addFieldFeedback();var i=e.error,n=e.warning,r=e.info,a=e.when,s=u.FieldFeedbackType.Error;if("valid"===a?s=u.FieldFeedbackType.WhenValid:n?s=u.FieldFeedbackType.Warning:r&&(s=u.FieldFeedbackType.Info),s===u.FieldFeedbackType.WhenValid&&(i||n||r))throw new Error('Cannot have an attribute (error, warning...) with FieldFeedback when="valid"');return l.state={validation:{key:l.key,type:s,show:void 0},validationMessage:""},l}var ne,re=(r(ae,ne=p.Component),ae.prototype.componentDidMount=function(){this.context.form.addFieldWillValidateEventListener(this.fieldWillValidate),this.context.form.addFieldDidValidateEventListener(this.fieldDidValidate),this.context.form.addFieldDidResetEventListener(this.fieldDidReset)},ae.prototype.componentWillUnmount=function(){this.context.form.removeFieldWillValidateEventListener(this.fieldWillValidate),this.context.form.removeFieldDidValidateEventListener(this.fieldDidValidate),this.context.form.removeFieldDidResetEventListener(this.fieldDidReset)},ae.prototype.fieldValidationStates=function(){var e=this.state.field,t=[];return void 0!==e&&("pending"===e?t.push("isPending"):(e.hasErrors()&&t.push("hasErrors"),e.hasWarnings()&&t.push("hasWarnings"),e.hasInfos()&&t.push("hasInfos"),e.isValid()&&t.push("isValid"))),t},ae.prototype.render=function(){var e=this.props,t=e.innerRef,i=e.className,n=e.classes,r=v(e,["innerRef","className","classes"]),a=this.fieldValidationStates(),s=i;return a.forEach(function(e){var t=n[e];void 0!==t&&(void 0!==s?s+=" "+t:s=t)}),p.createElement("input",h({ref:t},r,{className:s}))},ae.contextTypes={form:e.instanceOf(_).isRequired},ae.defaultProps={classes:{isPending:"is-pending",hasErrors:"has-errors",hasWarnings:"has-warnings",hasInfos:"has-infos",isValid:"is-valid"}},ae);function ae(){var t=null!==ne&&ne.apply(this,arguments)||this;return t.state={field:void 0},t.fieldWillValidate=function(e){e===t.props.name&&t.setState({field:"pending"})},t.fieldDidValidate=function(e){e.name===t.props.name&&t.setState({field:e})},t.fieldDidReset=function(e){e.name===t.props.name&&t.setState({field:void 0})},t}u.Async=Q,u.EventEmitter=a,u.Field=D,u.FieldDidResetEvent=F,u.FieldDidValidateEvent=y,u.FieldFeedback=te,u.FieldFeedbackWhenValid=Z,u.FieldFeedbacks=K,u.FieldWillValidateEvent=c,u.FieldsStore=x,u.FormWithConstraints=_,u.IValidityState=b,u.Input=re,u.InputElement=w,u.ValidateFieldEvent=s,u.deepForEach=function i(e,n){p.Children.forEach(e,function(e){var t=e;t.props&&t.props.children&&"object"==typeof t.props.children&&i(t.props.children,n),n(t)})},u.isHTMLInput=g,u.withFieldDidResetEventEmitter=E,u.withFieldDidValidateEventEmitter=m,u.withFieldWillValidateEventEmitter=f,u.withValidateFieldEventEmitter=o,Object.defineProperty(u,"__esModule",{value:!0})});
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("react"),require("prop-types")):"function"==typeof define&&define.amd?define(["exports","react","prop-types"],t):t((e=e||self).ReactFormWithConstraints={},e.React,e.PropTypes)}(this,function(u,p,e){"use strict";var n=function(e,t){return(n=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var i in t)t.hasOwnProperty(i)&&(e[i]=t[i])})(e,t)};function r(e,t){function i(){this.constructor=e}n(e,t),e.prototype=null===t?Object.create(t):(i.prototype=t.prototype,new i)}var h=function(){return(h=Object.assign||function(e){for(var t,i=1,n=arguments.length;i<n;i++)for(var r in t=arguments[i])Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r]);return e}).apply(this,arguments)};function v(e,t){var i={};for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&t.indexOf(n)<0&&(i[n]=e[n]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var r=0;for(n=Object.getOwnPropertySymbols(e);r<n.length;r++)t.indexOf(n[r])<0&&Object.prototype.propertyIsEnumerable.call(e,n[r])&&(i[n[r]]=e[n[r]])}return i}function l(a,s,o,l){return new(o=o||Promise)(function(e,t){function i(e){try{r(l.next(e))}catch(e){t(e)}}function n(e){try{r(l.throw(e))}catch(e){t(e)}}function r(t){t.done?e(t.value):new o(function(e){e(t.value)}).then(i,n)}r((l=l.apply(a,s||[])).next())})}function d(i,n){var r,a,s,e,o={label:0,sent:function(){if(1&s[0])throw s[1];return s[1]},trys:[],ops:[]};return e={next:t(0),throw:t(1),return:t(2)},"function"==typeof Symbol&&(e[Symbol.iterator]=function(){return this}),e;function t(t){return function(e){return function(t){if(r)throw new TypeError("Generator is already executing.");for(;o;)try{if(r=1,a&&(s=2&t[0]?a.return:t[0]?a.throw||((s=a.return)&&s.call(a),0):a.next)&&!(s=s.call(a,t[1])).done)return s;switch(a=0,s&&(t=[2&t[0],s.value]),t[0]){case 0:case 1:s=t;break;case 4:return o.label++,{value:t[1],done:!1};case 5:o.label++,a=t[1],t=[0];continue;case 7:t=o.ops.pop(),o.trys.pop();continue;default:if(!(s=0<(s=o.trys).length&&s[s.length-1])&&(6===t[0]||2===t[0])){o=0;continue}if(3===t[0]&&(!s||t[1]>s[0]&&t[1]<s[3])){o.label=t[1];break}if(6===t[0]&&o.label<s[1]){o.label=s[1],s=t;break}if(s&&o.label<s[2]){o.label=s[2],o.ops.push(t);break}s[2]&&o.ops.pop(),o.trys.pop();continue}t=n.call(i,o)}catch(e){t=[6,e],a=0}finally{r=s=0}if(5&t[0])throw t[1];return{value:t[0]?t[1]:void 0,done:!0}}([t,e])}}}function i(){for(var e=0,t=0,i=arguments.length;t<i;t++)e+=arguments[t].length;var n=Array(e),r=0;for(t=0;t<i;t++)for(var a=arguments[t],s=0,o=a.length;s<o;s++,r++)n[r]=a[s];return n}var a=(t.prototype.emitSync=function(e){for(var t=[],i=1;i<arguments.length;i++)t[i-1]=arguments[i];var n=this.getListeners(e),r=new Array;return n.forEach(function(e){return r.push(e.apply(void 0,t))}),r},t.prototype.emitAsync=function(s){for(var o=[],e=1;e<arguments.length;e++)o[e-1]=arguments[e];return l(this,void 0,void 0,function(){var t,i,n,r,a;return d(this,function(e){switch(e.label){case 0:t=this.getListeners(s),i=new Array,n=0,e.label=1;case 1:return n<t.length?(a=(r=i).push,[4,t[n].apply(t,o)]):[3,4];case 2:a.apply(r,[e.sent()]),e.label=3;case 3:return n++,[3,1];case 4:return[2,i]}})})},t.prototype.getListeners=function(e){var t=this.listeners.get(e);return void 0!==t?(console.assert(0<t.length,"No listener for event '"+e+"'"),t):[]},t.prototype.addListener=function(e,t){this.listeners.has(e)||this.listeners.set(e,[]);var i=this.listeners.get(e);console.assert(-1===i.indexOf(t),"Listener already added for event '"+e+"'"),i.push(t)},t.prototype.removeListener=function(e,t){var i=this.listeners.get(e);console.assert(void 0!==i,"Unknown event '"+e+"'");var n=i.lastIndexOf(t);console.assert(-1<n,"Listener not found for event '"+e+"'"),i.splice(n,1),0===i.length&&this.listeners.delete(e)},t);function t(){this.listeners=new Map}var s="VALIDATE_FIELD_EVENT";function o(e){return r(t,i=e),t.prototype.emitValidateFieldEvent=function(e){return this.validateFieldEventEmitter.emitAsync(s,e)},t.prototype.addValidateFieldEventListener=function(e){this.validateFieldEventEmitter.addListener(s,e)},t.prototype.removeValidateFieldEventListener=function(e){this.validateFieldEventEmitter.removeListener(s,e)},t;function t(){var e=null!==i&&i.apply(this,arguments)||this;return e.validateFieldEventEmitter=new a,e}var i}var c="FIELD_WILL_VALIDATE_EVENT";function f(e){return r(t,i=e),t.prototype.emitFieldWillValidateEvent=function(e){return this.fieldWillValidateEventEmitter.emitSync(c,e)},t.prototype.addFieldWillValidateEventListener=function(e){this.fieldWillValidateEventEmitter.addListener(c,e)},t.prototype.removeFieldWillValidateEventListener=function(e){this.fieldWillValidateEventEmitter.removeListener(c,e)},t;function t(){var e=null!==i&&i.apply(this,arguments)||this;return e.fieldWillValidateEventEmitter=new a,e}var i}var y="FIELD_DID_VALIDATE_EVENT";function m(e){return r(t,i=e),t.prototype.emitFieldDidValidateEvent=function(e){return this.fieldDidValidateEventEmitter.emitSync(y,e)},t.prototype.addFieldDidValidateEventListener=function(e){this.fieldDidValidateEventEmitter.addListener(y,e)},t.prototype.removeFieldDidValidateEventListener=function(e){this.fieldDidValidateEventEmitter.removeListener(y,e)},t;function t(){var e=null!==i&&i.apply(this,arguments)||this;return e.fieldDidValidateEventEmitter=new a,e}var i}var F="FIELD_DID_RESET_EVENT";function E(e){return r(t,i=e),t.prototype.emitFieldDidResetEvent=function(e){return this.fieldDidResetEventEmitter.emitSync(F,e)},t.prototype.addFieldDidResetEventListener=function(e){this.fieldDidResetEventEmitter.addListener(F,e)},t.prototype.removeFieldDidResetEventListener=function(e){this.fieldDidResetEventEmitter.removeListener(F,e)},t;function t(){var e=null!==i&&i.apply(this,arguments)||this;return e.fieldDidResetEventEmitter=new a,e}var i}var b=function(e){this.badInput=e.badInput,this.customError=e.customError,this.patternMismatch=e.patternMismatch,this.rangeOverflow=e.rangeOverflow,this.rangeUnderflow=e.rangeUnderflow,this.stepMismatch=e.stepMismatch,this.tooLong=e.tooLong,this.tooShort=e.tooShort,this.typeMismatch=e.typeMismatch,this.valid=e.valid,this.valueMissing=e.valueMissing};function g(e){return void 0===e.props}var k,w=function(e){g(e)?(e=e,this.name=e.name,this.type=e.type,this.value=e.value,this.validity=new b(e.validity),this.validationMessage=e.validationMessage):(e=e,this.name=e.props.name,this.type=void 0,this.value=e.props.value,this.validity=void 0,this.validationMessage=void 0)};(k=u.FieldFeedbackType||(u.FieldFeedbackType={})).Error="error",k.Warning="warning",k.Info="info",k.WhenValid="whenValid";var V,D=(L.prototype.addOrReplaceValidation=function(t){var e=this.validations.findIndex(function(e){return e.key===t.key});-1<e?this.validations[e]=t:this.validations.push(t)},L.prototype.clearValidations=function(){!function(e){for(;e.length;)e.pop()}(this.validations)},L.prototype.hasFeedbacksOfType=function(t,i){return this.validations.some(function(e){return(void 0===i||e.key.startsWith(i+"."))&&e.type===t&&!0===e.show})},L.prototype.hasErrors=function(e){return this.hasFeedbacksOfType(u.FieldFeedbackType.Error,e)},L.prototype.hasWarnings=function(e){return this.hasFeedbacksOfType(u.FieldFeedbackType.Warning,e)},L.prototype.hasInfos=function(e){return this.hasFeedbacksOfType(u.FieldFeedbackType.Info,e)},L.prototype.hasFeedbacks=function(e){return this.hasErrors(e)||this.hasWarnings(e)||this.hasInfos(e)},L.prototype.isValid=function(){return!this.hasErrors()},L);function L(e){this.name=e,this.validations=[]}(V=u.FieldEvent||(u.FieldEvent={})).Added="FIELD_ADDED",V.Removed="FIELD_REMOVED";var S,x=(r(R,S=a),R.prototype.getField=function(t){var e=this.fields.filter(function(e){return e.name===t});return 1===e.length?e[0]:void 0},R.prototype.addField=function(t){var e=this.fields.filter(function(e){return e.name===t});if(console.assert(0===e.length||1===e.length,"Cannot have more than 1 field matching '"+t+"'"),0===e.length){var i=new D(t);this.fields.push(i),this.emitSync(u.FieldEvent.Added,i)}},R.prototype.removeField=function(t){var e=this.fields.filter(function(e){return e.name===t}),i=this.fields.indexOf(e[0]);-1<i&&(this.fields.splice(i,1),this.emitSync(u.FieldEvent.Removed,t))},R.prototype.isValid=function(){return this.fields.every(function(e){return e.isValid()})},R.prototype.hasFeedbacks=function(){return this.fields.some(function(e){return e.hasFeedbacks()})},R);function R(){var e=null!==S&&S.apply(this,arguments)||this;return e.fields=new Array,e}function O(e){return e.reduce(function(e,t){return e.concat(Array.isArray(t)?O(t):t)},[])}function W(e){return void 0!==e}var I,M=(r(T,I=p.PureComponent),T);function T(){return null!==I&&I.apply(this,arguments)||this}var N,_=(r(A,N=E(f(m(o(M))))),A.prototype.getChildContext=function(){return{form:this}},A.prototype.computeFieldFeedbacksKey=function(){return""+this.fieldFeedbacksKeyCounter++},A.prototype.validateFields=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return this._validateFields.apply(this,i([!0],e))},A.prototype.validateForm=function(){return this.validateFieldsWithoutFeedback()},A.prototype.validateFieldsWithoutFeedback=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return this._validateFields.apply(this,i([!1],e))},A.prototype._validateFields=function(s){for(var o=[],e=1;e<arguments.length;e++)o[e-1]=arguments[e];return l(this,void 0,void 0,function(){var t,i,n,r,a;return d(this,function(e){switch(e.label){case 0:t=new Array,i=this.normalizeInputs.apply(this,o),n=0,e.label=1;case 1:return n<i.length?(r=i[n],[4,this.validateField(s,new w(r),r)]):[3,4];case 2:void 0!==(a=e.sent())&&t.push(a),e.label=3;case 3:return n++,[3,1];case 4:return[2,t]}})})},A.prototype.validateField=function(r,a,s){return l(this,void 0,void 0,function(){var t,i,n;return d(this,function(e){switch(e.label){case 0:return t=a.name,void 0!==(i=this.fieldsStore.getField(t))?[3,1]:[3,3];case 1:return!r&&i.hasFeedbacks()?[3,3]:(i.element=s,i.clearValidations(),this.emitFieldWillValidateEvent(t),[4,this.emitValidateFieldEvent(a)]);case 2:n=e.sent(),console.assert(JSON.stringify(O(n).filter(W))===JSON.stringify(i.validations),"FieldsStore does not match emitValidateFieldEvent() result, did the user changed the input rapidly?"),this.emitFieldDidValidateEvent(i),e.label=3;case 3:return[2,i]}})})},A.prototype.normalizeInputs=function(){for(var e,r=this,t=[],i=0;i<arguments.length;i++)t[i]=arguments[i];return 0===t.length?(e=(e=Array.from(this.form.querySelectorAll("[name]"))).filter(function(e){return void 0!==e.validity})).filter(function(e){return"checkbox"!==e.type&&"radio"!==e.type}).map(function(e){return e.name}).forEach(function(e,t,i){if(i.indexOf(e)!==t)throw new Error("Multiple elements matching '[name=\""+e+"\"]' inside the form")}):e=t.map(function(e){if("string"!=typeof e)return e;var t='[name="'+e+'"]',i=Array.from(r.form.querySelectorAll(t));if(0<i.filter(function(e){return void 0===e.validity}).length)throw new Error("'"+t+"' should match an <input>, <select> or <textarea>");if(1<i.filter(function(e){return"checkbox"!==e.type&&"radio"!==e.type}).length)throw new Error("Multiple elements matching '"+t+"' inside the form");var n=i[0];if(void 0===n)throw new Error("Could not find field '"+t+"' inside the form");return n}),e},A.prototype.isValid=function(){return this.fieldsStore.isValid()},A.prototype.hasFeedbacks=function(){return this.fieldsStore.hasFeedbacks()},A.prototype.reset=function(){return this.resetFields()},A.prototype.resetFields=function(){for(var i=this,e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];var n=new Array;return this.normalizeInputs.apply(this,e).forEach(function(e){var t=i.resetField(new w(e));void 0!==t&&n.push(t)}),n},A.prototype.resetField=function(e){var t=e.name,i=this.fieldsStore.getField(t);return void 0===i||(i.clearValidations(),this.emitFieldDidResetEvent(i)),i},A.prototype.render=function(){var t=this;return p.createElement("form",h({ref:function(e){return t.form=e}},this.props))},A.childContextTypes={form:e.instanceOf(A).isRequired},A);function A(){var e=null!==N&&N.apply(this,arguments)||this;return e.form=null,e.fieldsStore=new x,e.fieldFeedbacksKeyCounter=0,e}var C,P=(r(j,C=p.PureComponent),j);function j(){return null!==C&&C.apply(this,arguments)||this}var q,U,K=(r(z,q=o(P)),z.prototype.getChildContext=function(){return{fieldFeedbacks:this}},z.prototype.computeFieldFeedbackKey=function(){return this.key+"."+this.fieldFeedbackKeyCounter++},z.prototype.addFieldFeedback=function(){return this.computeFieldFeedbackKey()},z.prototype.componentDidMount=function(){var e=this.context,t=e.form,i=e.fieldFeedbacks;t.fieldsStore.addField(this.fieldName),(i||t).addValidateFieldEventListener(this.validate)},z.prototype.componentWillUnmount=function(){var e=this.context,t=e.form,i=e.fieldFeedbacks;t.fieldsStore.removeField(this.fieldName),(i||t).removeValidateFieldEventListener(this.validate)},z.prototype._validate=function(t){return l(this,void 0,void 0,function(){return d(this,function(e){switch(e.label){case 0:return[4,this.emitValidateFieldEvent(t)];case 1:return[2,O(e.sent())]}})})},z.prototype.render=function(){var e=this.props.children;return void 0!==e?e:null},z.defaultProps={stop:"first-error"},z.contextTypes={form:e.instanceOf(_).isRequired,fieldFeedbacks:e.instanceOf(z)},z.childContextTypes={fieldFeedbacks:e.instanceOf(z).isRequired},z);function z(e,t){var i=q.call(this,e,t)||this;i.fieldFeedbackKeyCounter=0,i.validate=function(s){return l(i,void 0,void 0,function(){var t,i,n,r,a;return d(this,function(e){switch(e.label){case 0:return(t=this.context,i=t.form,n=t.fieldFeedbacks,s.name!==this.fieldName)?[3,3]:(a=i.fieldsStore.getField(this.fieldName),n&&("first"===n.props.stop&&a.hasFeedbacks(n.key)||"first-error"===n.props.stop&&a.hasErrors(n.key)||"first-warning"===n.props.stop&&a.hasWarnings(n.key)||"first-info"===n.props.stop&&a.hasInfos(n.key))?[3,3]:[3,1]);case 1:return[4,this._validate(s)];case 2:r=e.sent(),e.label=3;case 3:return[2,r]}})})};var n=t.form,r=t.fieldFeedbacks;if(i.key=r?r.computeFieldFeedbackKey():n.computeFieldFeedbacksKey(),r){if(i.fieldName=r.fieldName,void 0!==e.for)throw new Error("FieldFeedbacks cannot have a parent and a 'for' prop")}else{if(void 0===e.for)throw new Error("FieldFeedbacks cannot be without parent and without 'for' prop");i.fieldName=e.for}return i}(U=u.Status||(u.Status={}))[U.None=0]="None",U[U.Pending=1]="Pending",U[U.Rejected=2]="Rejected",U[U.Resolved=3]="Resolved";var J,G=(r(H,J=p.PureComponent),H);function H(){return null!==J&&J.apply(this,arguments)||this}var B,Q=(r(X,B=o(G)),X.prototype.getChildContext=function(){return{async:this}},X.prototype.componentDidMount=function(){this.context.fieldFeedbacks.addValidateFieldEventListener(this.validate)},X.prototype.componentWillUnmount=function(){this.context.fieldFeedbacks.removeValidateFieldEventListener(this.validate)},X.prototype._validate=function(n){return l(this,void 0,void 0,function(){var t,i;return d(this,function(e){switch(e.label){case 0:this.setState({status:u.Status.Pending}),e.label=1;case 1:return e.trys.push([1,3,,4]),[4,this.props.promise(n.value)];case 2:return t=e.sent(),this.setState({status:u.Status.Resolved,value:t}),[3,4];case 3:return i=e.sent(),this.setState({status:u.Status.Rejected,value:i}),[3,4];case 4:return[2,this.emitValidateFieldEvent(n)]}})})},X.prototype.render=function(){var e=this.props,t=this.state,i=null;switch(t.status){case u.Status.None:break;case u.Status.Pending:e.pending&&(i=e.pending);break;case u.Status.Resolved:e.then&&(i=e.then(t.value));break;case u.Status.Rejected:e.catch&&(i=e.catch(t.value));break;default:console.assert(!1,"Unknown status: '"+t.status+"'")}return i},X.contextTypes={form:e.instanceOf(_).isRequired,fieldFeedbacks:e.instanceOf(K).isRequired},X.childContextTypes={async:e.instanceOf(X).isRequired},X);function X(){var s=null!==B&&B.apply(this,arguments)||this;return s.state={status:u.Status.None},s.validate=function(e){var t,i=s.context,n=i.form,r=i.fieldFeedbacks,a=n.fieldsStore.getField(e.name);return"first"===r.props.stop&&a.hasFeedbacks(r.key)||"first-error"===r.props.stop&&a.hasErrors(r.key)||"first-warning"===r.props.stop&&a.hasWarnings(r.key)||"first-info"===r.props.stop&&a.hasInfos(r.key)?s.setState({status:u.Status.None}):t=s._validate(e),t},s}var Y,Z=(r($,Y=p.Component),$.prototype.componentDidMount=function(){this.context.form.addFieldWillValidateEventListener(this.fieldWillValidate),this.context.form.addFieldDidValidateEventListener(this.fieldDidValidate),this.context.form.addFieldDidResetEventListener(this.fieldDidReset)},$.prototype.componentWillUnmount=function(){this.context.form.removeFieldWillValidateEventListener(this.fieldWillValidate),this.context.form.removeFieldDidValidateEventListener(this.fieldDidValidate),this.context.form.removeFieldDidResetEventListener(this.fieldDidReset)},$.prototype.render=function(){var e=this.props,t=e.style,i=v(e,["style"]);return this.state.fieldIsValid?p.createElement("span",h({},i,{style:h({display:"block"},t)})):null},$.contextTypes={form:e.instanceOf(_).isRequired,fieldFeedbacks:e.instanceOf(K).isRequired},$);function $(){var t=null!==Y&&Y.apply(this,arguments)||this;return t.state={fieldIsValid:void 0},t.fieldWillValidate=function(e){e===t.context.fieldFeedbacks.fieldName&&t.setState({fieldIsValid:void 0})},t.fieldDidValidate=function(e){e.name===t.context.fieldFeedbacks.fieldName&&t.setState({fieldIsValid:e.isValid()})},t.fieldDidReset=function(e){e.name===t.context.fieldFeedbacks.fieldName&&t.setState({fieldIsValid:void 0})},t}var ee,te=(r(ie,ee=p.Component),ie.prototype.componentDidMount=function(){var e=this.context,t=e.form,i=e.fieldFeedbacks,n=e.async;n?n.addValidateFieldEventListener(this.validate):i.addValidateFieldEventListener(this.validate),t.addFieldDidResetEventListener(this.fieldDidReset)},ie.prototype.componentWillUnmount=function(){var e=this.context,t=e.form,i=e.fieldFeedbacks,n=e.async;n?n.removeValidateFieldEventListener(this.validate):i.removeValidateFieldEventListener(this.validate),t.removeFieldDidResetEventListener(this.fieldDidReset)},ie.prototype.render=function(){var e=this.props,t=(e.when,e.error,e.warning,e.info,e.className),i=e.classes,n=e.style,r=e.children,a=v(e,["when","error","warning","info","className","classes","style","children"]),s=this.state,o=s.validation,l=s.validationMessage,d=i[o.type],c=void 0!==t?t+" "+d:d;if(o.type===u.FieldFeedbackType.WhenValid)return p.createElement(Z,h({"data-feedback":this.key,style:n,className:c},a),r);if(o.show){var f=void 0!==r?r:l;return p.createElement("span",h({"data-feedback":this.key,className:c,style:h({display:"block"},n)},a),f)}return null},ie.defaultProps={when:function(){return!0},classes:{error:"error",warning:"warning",info:"info",whenValid:"when-valid"}},ie.contextTypes={form:e.instanceOf(_).isRequired,fieldFeedbacks:e.instanceOf(K).isRequired,async:e.instanceOf(Q)},ie);function ie(e,t){var l=ee.call(this,e,t)||this;l.validate=function(e){var t=l.props.when,i=l.context,n=i.form,r=i.fieldFeedbacks,a=n.fieldsStore.getField(e.name),s=h({},l.state.validation);if("first"===r.props.stop&&a.hasFeedbacks(r.key)||"first-error"===r.props.stop&&a.hasErrors(r.key)||"first-warning"===r.props.stop&&a.hasWarnings(r.key)||"first-info"===r.props.stop&&a.hasInfos(r.key))s.show=void 0;else if(s.show=!1,"function"==typeof t)s.show=t(e.value);else{if("string"!=typeof t)throw new TypeError("Invalid FieldFeedback 'when' type: "+typeof t);if("valid"===t)s.show=void 0;else{var o=e.validity;o.valid||("*"===t||o.badInput&&"badInput"===t||o.patternMismatch&&"patternMismatch"===t||o.rangeOverflow&&"rangeOverflow"===t||o.rangeUnderflow&&"rangeUnderflow"===t||o.stepMismatch&&"stepMismatch"===t||o.tooLong&&"tooLong"===t||o.tooShort&&"tooShort"===t||o.typeMismatch&&"typeMismatch"===t||o.valueMissing&&"valueMissing"===t)&&(s.show=!0)}}return a.addOrReplaceValidation(s),l.setState({validation:s,validationMessage:e.validationMessage}),s},l.fieldDidReset=function(e){e.name===l.context.fieldFeedbacks.fieldName&&l.setState(function(e){return{validation:h(h({},e.validation),{show:void 0}),validationMessage:""}})},l.key=t.fieldFeedbacks.addFieldFeedback();var i=e.error,n=e.warning,r=e.info,a=e.when,s=u.FieldFeedbackType.Error;if("valid"===a?s=u.FieldFeedbackType.WhenValid:n?s=u.FieldFeedbackType.Warning:r&&(s=u.FieldFeedbackType.Info),s===u.FieldFeedbackType.WhenValid&&(i||n||r))throw new Error('Cannot have an attribute (error, warning...) with FieldFeedback when="valid"');return l.state={validation:{key:l.key,type:s,show:void 0},validationMessage:""},l}var ne,re=(r(ae,ne=p.Component),ae.prototype.componentDidMount=function(){this.context.form.addFieldWillValidateEventListener(this.fieldWillValidate),this.context.form.addFieldDidValidateEventListener(this.fieldDidValidate),this.context.form.addFieldDidResetEventListener(this.fieldDidReset)},ae.prototype.componentWillUnmount=function(){this.context.form.removeFieldWillValidateEventListener(this.fieldWillValidate),this.context.form.removeFieldDidValidateEventListener(this.fieldDidValidate),this.context.form.removeFieldDidResetEventListener(this.fieldDidReset)},ae.prototype.fieldValidationStates=function(){var e=this.state.field,t=[];return void 0!==e&&("pending"===e?t.push("isPending"):(e.hasErrors()&&t.push("hasErrors"),e.hasWarnings()&&t.push("hasWarnings"),e.hasInfos()&&t.push("hasInfos"),e.isValid()&&t.push("isValid"))),t},ae.prototype.render=function(){var e=this.props,t=e.innerRef,i=e.className,n=e.classes,r=v(e,["innerRef","className","classes"]),a=this.fieldValidationStates(),s=i;return a.forEach(function(e){var t=n[e];void 0!==t&&(void 0!==s?s+=" "+t:s=t)}),p.createElement("input",h({ref:t},r,{className:s}))},ae.contextTypes={form:e.instanceOf(_).isRequired},ae.defaultProps={classes:{isPending:"is-pending",hasErrors:"has-errors",hasWarnings:"has-warnings",hasInfos:"has-infos",isValid:"is-valid"}},ae);function ae(){var t=null!==ne&&ne.apply(this,arguments)||this;return t.state={field:void 0},t.fieldWillValidate=function(e){e===t.props.name&&t.setState({field:"pending"})},t.fieldDidValidate=function(e){e.name===t.props.name&&t.setState({field:e})},t.fieldDidReset=function(e){e.name===t.props.name&&t.setState({field:void 0})},t}u.Async=Q,u.EventEmitter=a,u.Field=D,u.FieldDidResetEvent=F,u.FieldDidValidateEvent=y,u.FieldFeedback=te,u.FieldFeedbackWhenValid=Z,u.FieldFeedbacks=K,u.FieldWillValidateEvent=c,u.FieldsStore=x,u.FormWithConstraints=_,u.IValidityState=b,u.Input=re,u.InputElement=w,u.ValidateFieldEvent=s,u.deepForEach=function i(e,n){p.Children.forEach(e,function(e){var t=e;t.props&&t.props.children&&"object"==typeof t.props.children&&i(t.props.children,n),n(t)})},u.isHTMLInput=g,u.withFieldDidResetEventEmitter=E,u.withFieldDidValidateEventEmitter=m,u.withFieldWillValidateEventEmitter=f,u.withValidateFieldEventEmitter=o,Object.defineProperty(u,"__esModule",{value:!0})});
//# sourceMappingURL=react-form-with-constraints.production.min.js.map

@@ -138,9 +138,7 @@ "use strict";

input = inputs[i];
return [4, this.validateField(forceValidateFields, new InputElement_1.InputElement(input))];
return [4, this.validateField(forceValidateFields, new InputElement_1.InputElement(input), input)];
case 2:
field = _a.sent();
if (field !== undefined) {
field.element = input;
if (field !== undefined)
fields.push(field);
}
_a.label = 3;

@@ -155,3 +153,3 @@ case 3:

};
FormWithConstraints.prototype.validateField = function (forceValidateFields, input) {
FormWithConstraints.prototype.validateField = function (forceValidateFields, input, nativeInput) {
return __awaiter(this, void 0, void 0, function () {

@@ -168,2 +166,3 @@ var fieldName, field, arrayOfArrays;

if (!(forceValidateFields || !field.hasFeedbacks())) return [3, 3];
field.element = nativeInput;
field.clearValidations();

@@ -170,0 +169,0 @@ this.emitFieldWillValidateEvent(fieldName);

@@ -42,11 +42,9 @@ import * as React from 'react';

const input = inputs[i];
const field = await this.validateField(forceValidateFields, new InputElement(input));
if (field !== undefined) {
field.element = input;
const field = await this.validateField(forceValidateFields, new InputElement(input), input);
if (field !== undefined)
fields.push(field);
}
}
return fields;
}
async validateField(forceValidateFields, input) {
async validateField(forceValidateFields, input, nativeInput) {
const fieldName = input.name;

@@ -57,2 +55,3 @@ const field = this.fieldsStore.getField(fieldName);

else if (forceValidateFields || !field.hasFeedbacks()) {
field.element = nativeInput;
field.clearValidations();

@@ -59,0 +58,0 @@ this.emitFieldWillValidateEvent(fieldName);

{
"name": "react-form-with-constraints",
"version": "0.15.0",
"version": "0.15.1",
"repository": {

@@ -71,3 +71,3 @@ "type": "git",

},
"gitHead": "260397f5d1dd0691faf931c7dd86ceecc8e6d349"
"gitHead": "ea6bcc21728092e8195343a48f48050ea1fcce49"
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc