react-form-with-constraints
Advanced tools
Comparing version 0.6.1 to 0.6.2
@@ -429,3 +429,3 @@ (function (global, factory) { | ||
else { | ||
console.assert(false, "Invalid FieldFeedback 'when': " + when); | ||
throw new TypeError("Invalid FieldFeedback 'when' type: " + typeof when); | ||
} | ||
@@ -432,0 +432,0 @@ var field = this.context.form.fieldsStore.cloneField(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.ReactFormWithConstraints={},e.React,e.PropTypes)}(this,function(e,t,n){"use strict";function r(e,t){function n(){this.constructor=e}l(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}function i(e,t){var n={};for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols)for(var i=0,r=Object.getOwnPropertySymbols(e);i<r.length;i++)t.indexOf(r[i])<0&&(n[r[i]]=e[r[i]]);return n}function o(e,t){var n="function"==typeof Symbol&&e[Symbol.iterator];if(!n)return e;var r,i,o=n.call(e),s=[];try{for(;(void 0===t||t-- >0)&&!(r=o.next()).done;)s.push(r.value)}catch(e){i={error:e}}finally{try{r&&!r.done&&(n=o.return)&&n.call(o)}finally{if(i)throw i.error}}return s}function s(){for(var e=[],t=0;t<arguments.length;t++)e=e.concat(o(arguments[t]));return e}function a(e){return function(e){function t(){var t=null!==e&&e.apply(this,arguments)||this;return t.validateEventEmitter=new f,t}return r(t,e),t.prototype.emitValidateEvent=function(e){this.validateEventEmitter.emit(c,e)},t.prototype.addValidateEventListener=function(e){this.validateEventEmitter.addListener(c,e)},t.prototype.removeValidateEventListener=function(e){this.validateEventEmitter.removeListener(c,e)},t}(e)}var l=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)t.hasOwnProperty(n)&&(e[n]=t[n])},d=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++){t=arguments[n];for(var i in t)Object.prototype.hasOwnProperty.call(t,i)&&(e[i]=t[i])}return e},f=function(){function e(){this.listeners=new Map}return e.prototype.emit=function(e){for(var t=[],n=1;n<arguments.length;n++)t[n-1]=arguments[n];var r=this.listeners.get(e);void 0!==r&&(console.assert(r.length>0,"No listener for event '"+e+"'"),r.forEach(function(e){return e.apply(void 0,s(t))}))},e.prototype.addListener=function(e,t){this.listeners.has(e)||this.listeners.set(e,[]);var n=this.listeners.get(e);console.assert(-1===n.indexOf(t),"Listener already added for event '"+e+"'"),n.push(t)},e.prototype.removeListener=function(e,t){var n=this.listeners.get(e);console.assert(void 0!==n,"Unknown event '"+e+"'");var r=n.lastIndexOf(t);console.assert(r>-1,"Listener not found for event '"+e+"'"),n.splice(r,1),0===n.length&&this.listeners.delete(e)},e}(),c="VALIDATE_EVENT",p={dirty:!1,errors:new Set,warnings:new Set,infos:new Set,validationMessage:""};!function(e){e.Added="FIELD_ADDED",e.Removed="FIELD_REMOVED",e.Updated="FIELD_UPDATED"}(e.FieldEvent||(e.FieldEvent={}));var u=function(t){function n(){var e=null!==t&&t.apply(this,arguments)||this;return e.fields=Object.create(null),e}return r(n,t),n.prototype.addField=function(t){if(void 0===this.fields[t]){var n=p;this.fields[t]=n,this.emit(e.FieldEvent.Added,t,n)}},n.prototype.removeField=function(t){console.assert(void 0!==this.fields[t],"Unknown field '"+t+"'"),delete this.fields[t],this.emit(e.FieldEvent.Removed,t)},n.prototype.cloneField=function(e){var t=this.fields[e];return console.assert(void 0!==t,"Unknown field '"+e+"'"),{dirty:t.dirty,errors:new Set(t.errors),warnings:new Set(t.warnings),infos:new Set(t.infos),validationMessage:t.validationMessage}},n.prototype.updateField=function(t,n){console.assert(void 0!==this.fields[t],"Unknown field '"+t+"'"),this.fields[t]=n,this.emit(e.FieldEvent.Updated,t)},n.prototype.removeFieldFor=function(t,n){var r=this.fields[t];console.assert(void 0!==r,"Unknown field '"+t+"'");var i=function(e){return n!==Math.floor(e)};r.errors=new Set(s(r.errors).filter(i)),r.warnings=new Set(s(r.warnings).filter(i)),r.infos=new Set(s(r.infos).filter(i)),this.emit(e.FieldEvent.Updated,t)},n.prototype.getFieldFor=function(e,t){var n=this.fields[e];console.assert(void 0!==n,"Unknown field '"+e+"'");var r=function(e){return t===Math.floor(e)};return{dirty:n.dirty,errors:new Set(s(n.errors).filter(r)),warnings:new Set(s(n.warnings).filter(r)),infos:new Set(s(n.infos).filter(r)),validationMessage:n.validationMessage}},n.prototype.containErrors=function(){for(var e=this,t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];return t.some(function(t){var n=e.fields[t];return void 0!==n&&n.errors.size>0})},n.prototype.containWarnings=function(){for(var e=this,t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];return t.some(function(t){var n=e.fields[t];return void 0!==n&&n.warnings.size>0})},n.prototype.containInfos=function(){for(var e=this,t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];return t.some(function(t){var n=e.fields[t];return void 0!==n&&n.infos.size>0})},n.prototype.areValidDirtyWithoutWarnings=function(){for(var e=this,t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];return t.some(function(t){var n=e.fields[t];return void 0!==n&&!0===n.dirty&&0===n.errors.size&&0===n.warnings.size})},n}(f),h=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return r(t,e),t}(t.Component),v=function(e){function o(){var t=null!==e&&e.apply(this,arguments)||this;return t.fieldsStore=new u,t.fieldFeedbacksKey=0,t}return r(o,e),o.prototype.getChildContext=function(){return{form:this}},o.prototype.computeFieldFeedbacksKey=function(){return this.fieldFeedbacksKey++},o.prototype.validateFields=function(){for(var e=this,t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];var r=t.filter(function(e){return"string"!=typeof e}),i=t.filter(function(e){return"string"==typeof e}),o=[];if(0===t.length&&(o=this.form.querySelectorAll("[name]")),i.length>0){var a=i.map(function(e){return'[name="'+e+'"]'});o=this.form.querySelectorAll(a.join(", "))}s(r,o).forEach(function(t){return e.emitValidateEvent(t)})},o.prototype.isValid=function(){var e=Object.keys(this.fieldsStore.fields);return!(t=this.fieldsStore).containErrors.apply(t,s(e));var t},o.prototype.render=function(){var e=this,n=this.props,r=n.children,o=i(n,["children"]);return t.createElement("form",d({ref:function(t){return e.form=t}},o),r)},o.childContextTypes={form:n.object.isRequired},o}(a(h)),y=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return r(t,e),t}(t.Component),m=function(o){function s(e,t){var n=o.call(this,e)||this;return n.fieldFeedbackKey=0,n.validate=n.validate.bind(n),n.reRender=n.reRender.bind(n),n.key=t.form.computeFieldFeedbacksKey(),n}return r(s,o),s.prototype.getChildContext=function(){return{fieldFeedbacks:this}},s.prototype.computeFieldFeedbackKey=function(){return this.key+this.fieldFeedbackKey++/10},s.prototype.componentWillMount=function(){var t=this.props.for;this.context.form.fieldsStore.addField(t),this.context.form.addValidateEventListener(this.validate),this.context.form.fieldsStore.addListener(e.FieldEvent.Updated,this.reRender)},s.prototype.componentWillUnmount=function(){var t=this.props.for;this.context.form.fieldsStore.removeField(t),this.context.form.removeValidateEventListener(this.validate),this.context.form.fieldsStore.removeListener(e.FieldEvent.Updated,this.reRender)},s.prototype.validate=function(e){var t=this.props.for;e.name===t&&(this.context.form.fieldsStore.removeFieldFor(t,this.key),this.emitValidateEvent(e))},s.prototype.reRender=function(e){this.props.for===e&&this.forceUpdate()},s.prototype.render=function(){var e=this.props,n=(e.for,e.show,e.children),r=i(e,["for","show","children"]);return t.createElement("div",d({},r),n)},s.defaultProps={show:"first"},s.contextTypes={form:n.object.isRequired},s.childContextTypes={fieldFeedbacks:n.object.isRequired},s}(a(y)),F=function(e){function o(t,n){var r=e.call(this,t)||this;return r.validate=r.validate.bind(r),r.key=n.fieldFeedbacks.computeFieldFeedbackKey(),r}return r(o,e),o.prototype.componentWillMount=function(){this.context.fieldFeedbacks.addValidateEventListener(this.validate)},o.prototype.componentWillUnmount=function(){this.context.fieldFeedbacks.removeValidateEventListener(this.validate)},o.prototype.validate=function(e){var t=this.props,n=t.when,r=t.warning,i=t.info,o=this.context.fieldFeedbacks.props.for,s=!1;if("function"==typeof n)n(e.value)&&(s=!0);else if("string"==typeof n){var a=e.validity;a.valid||("*"===n?s=!0:(a.badInput&&"badInput"===n||a.patternMismatch&&"patternMismatch"===n||a.rangeOverflow&&"rangeOverflow"===n||a.rangeUnderflow&&"rangeUnderflow"===n||a.stepMismatch&&"stepMismatch"===n||a.tooLong&&"tooLong"===n||a.tooShort&&"tooShort"===n||a.typeMismatch&&"typeMismatch"===n||a.valueMissing&&"valueMissing"===n)&&(s=!0))}else console.assert(!1,"Invalid FieldFeedback 'when': "+n);var l=this.context.form.fieldsStore.cloneField(o);l.dirty=!0,l.validationMessage=e.validationMessage,s&&(r?l.warnings.add(this.key):i?l.infos.add(this.key):l.errors.add(this.key)),this.context.form.fieldsStore.updateField(o,l)},o.prototype.render=function(){var e,n=this.props,r=(n.when,n.error,n.warning,n.info,n.className),o=n.children,s=i(n,["when","error","warning","info","className","children"]),a=this.context.fieldFeedbacks.props,l=a.for,f=a.show,c=this.context.form.fieldsStore.getFieldFor(l,this.context.fieldFeedbacks.key),p=c.errors,u=c.warnings,h=c.infos,v=c.validationMessage,y=p.values().next().value,m=u.values().next().value;p.has(this.key)&&("all"===f||"first"===f&&y===this.key)?e="error":u.has(this.key)&&0===p.size&&("all"===f||"first"===f&&m===this.key)?e="warning":h.has(this.key)&&(e="info");var F=null;return void 0!==e&&(e=void 0!==r?r+" "+e:e,F=void 0!==o?o:v),null!==F?t.createElement("div",d({},s,{className:e}),F):null},o.contextTypes={form:n.object.isRequired,fieldFeedbacks:n.object.isRequired},o}(t.Component);e.fieldWithoutFeedback=p,e.FormWithConstraintsComponent=h,e.FormWithConstraints=v,e.FieldFeedbacksComponent=y,e.FieldFeedbacks=m,e.FieldFeedback=F,e.FieldsStore=u,e.EventEmitter=f,e.ValidateEvent=c,e.withValidateEventEmitter=a,Object.defineProperty(e,"__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.ReactFormWithConstraints={},e.React,e.PropTypes)}(this,function(e,t,n){"use strict";function r(e,t){function n(){this.constructor=e}l(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}function i(e,t){var n={};for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols)for(var i=0,r=Object.getOwnPropertySymbols(e);i<r.length;i++)t.indexOf(r[i])<0&&(n[r[i]]=e[r[i]]);return n}function o(e,t){var n="function"==typeof Symbol&&e[Symbol.iterator];if(!n)return e;var r,i,o=n.call(e),s=[];try{for(;(void 0===t||t-- >0)&&!(r=o.next()).done;)s.push(r.value)}catch(e){i={error:e}}finally{try{r&&!r.done&&(n=o.return)&&n.call(o)}finally{if(i)throw i.error}}return s}function s(){for(var e=[],t=0;t<arguments.length;t++)e=e.concat(o(arguments[t]));return e}function a(e){return function(e){function t(){var t=null!==e&&e.apply(this,arguments)||this;return t.validateEventEmitter=new f,t}return r(t,e),t.prototype.emitValidateEvent=function(e){this.validateEventEmitter.emit(c,e)},t.prototype.addValidateEventListener=function(e){this.validateEventEmitter.addListener(c,e)},t.prototype.removeValidateEventListener=function(e){this.validateEventEmitter.removeListener(c,e)},t}(e)}var l=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)t.hasOwnProperty(n)&&(e[n]=t[n])},d=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++){t=arguments[n];for(var i in t)Object.prototype.hasOwnProperty.call(t,i)&&(e[i]=t[i])}return e},f=function(){function e(){this.listeners=new Map}return e.prototype.emit=function(e){for(var t=[],n=1;n<arguments.length;n++)t[n-1]=arguments[n];var r=this.listeners.get(e);void 0!==r&&(console.assert(r.length>0,"No listener for event '"+e+"'"),r.forEach(function(e){return e.apply(void 0,s(t))}))},e.prototype.addListener=function(e,t){this.listeners.has(e)||this.listeners.set(e,[]);var n=this.listeners.get(e);console.assert(-1===n.indexOf(t),"Listener already added for event '"+e+"'"),n.push(t)},e.prototype.removeListener=function(e,t){var n=this.listeners.get(e);console.assert(void 0!==n,"Unknown event '"+e+"'");var r=n.lastIndexOf(t);console.assert(r>-1,"Listener not found for event '"+e+"'"),n.splice(r,1),0===n.length&&this.listeners.delete(e)},e}(),c="VALIDATE_EVENT",p={dirty:!1,errors:new Set,warnings:new Set,infos:new Set,validationMessage:""};!function(e){e.Added="FIELD_ADDED",e.Removed="FIELD_REMOVED",e.Updated="FIELD_UPDATED"}(e.FieldEvent||(e.FieldEvent={}));var u=function(t){function n(){var e=null!==t&&t.apply(this,arguments)||this;return e.fields=Object.create(null),e}return r(n,t),n.prototype.addField=function(t){if(void 0===this.fields[t]){var n=p;this.fields[t]=n,this.emit(e.FieldEvent.Added,t,n)}},n.prototype.removeField=function(t){console.assert(void 0!==this.fields[t],"Unknown field '"+t+"'"),delete this.fields[t],this.emit(e.FieldEvent.Removed,t)},n.prototype.cloneField=function(e){var t=this.fields[e];return console.assert(void 0!==t,"Unknown field '"+e+"'"),{dirty:t.dirty,errors:new Set(t.errors),warnings:new Set(t.warnings),infos:new Set(t.infos),validationMessage:t.validationMessage}},n.prototype.updateField=function(t,n){console.assert(void 0!==this.fields[t],"Unknown field '"+t+"'"),this.fields[t]=n,this.emit(e.FieldEvent.Updated,t)},n.prototype.removeFieldFor=function(t,n){var r=this.fields[t];console.assert(void 0!==r,"Unknown field '"+t+"'");var i=function(e){return n!==Math.floor(e)};r.errors=new Set(s(r.errors).filter(i)),r.warnings=new Set(s(r.warnings).filter(i)),r.infos=new Set(s(r.infos).filter(i)),this.emit(e.FieldEvent.Updated,t)},n.prototype.getFieldFor=function(e,t){var n=this.fields[e];console.assert(void 0!==n,"Unknown field '"+e+"'");var r=function(e){return t===Math.floor(e)};return{dirty:n.dirty,errors:new Set(s(n.errors).filter(r)),warnings:new Set(s(n.warnings).filter(r)),infos:new Set(s(n.infos).filter(r)),validationMessage:n.validationMessage}},n.prototype.containErrors=function(){for(var e=this,t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];return t.some(function(t){var n=e.fields[t];return void 0!==n&&n.errors.size>0})},n.prototype.containWarnings=function(){for(var e=this,t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];return t.some(function(t){var n=e.fields[t];return void 0!==n&&n.warnings.size>0})},n.prototype.containInfos=function(){for(var e=this,t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];return t.some(function(t){var n=e.fields[t];return void 0!==n&&n.infos.size>0})},n.prototype.areValidDirtyWithoutWarnings=function(){for(var e=this,t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];return t.some(function(t){var n=e.fields[t];return void 0!==n&&!0===n.dirty&&0===n.errors.size&&0===n.warnings.size})},n}(f),h=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return r(t,e),t}(t.Component),v=function(e){function o(){var t=null!==e&&e.apply(this,arguments)||this;return t.fieldsStore=new u,t.fieldFeedbacksKey=0,t}return r(o,e),o.prototype.getChildContext=function(){return{form:this}},o.prototype.computeFieldFeedbacksKey=function(){return this.fieldFeedbacksKey++},o.prototype.validateFields=function(){for(var e=this,t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];var r=t.filter(function(e){return"string"!=typeof e}),i=t.filter(function(e){return"string"==typeof e}),o=[];if(0===t.length&&(o=this.form.querySelectorAll("[name]")),i.length>0){var a=i.map(function(e){return'[name="'+e+'"]'});o=this.form.querySelectorAll(a.join(", "))}s(r,o).forEach(function(t){return e.emitValidateEvent(t)})},o.prototype.isValid=function(){var e=Object.keys(this.fieldsStore.fields);return!(t=this.fieldsStore).containErrors.apply(t,s(e));var t},o.prototype.render=function(){var e=this,n=this.props,r=n.children,o=i(n,["children"]);return t.createElement("form",d({ref:function(t){return e.form=t}},o),r)},o.childContextTypes={form:n.object.isRequired},o}(a(h)),y=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return r(t,e),t}(t.Component),m=function(o){function s(e,t){var n=o.call(this,e)||this;return n.fieldFeedbackKey=0,n.validate=n.validate.bind(n),n.reRender=n.reRender.bind(n),n.key=t.form.computeFieldFeedbacksKey(),n}return r(s,o),s.prototype.getChildContext=function(){return{fieldFeedbacks:this}},s.prototype.computeFieldFeedbackKey=function(){return this.key+this.fieldFeedbackKey++/10},s.prototype.componentWillMount=function(){var t=this.props.for;this.context.form.fieldsStore.addField(t),this.context.form.addValidateEventListener(this.validate),this.context.form.fieldsStore.addListener(e.FieldEvent.Updated,this.reRender)},s.prototype.componentWillUnmount=function(){var t=this.props.for;this.context.form.fieldsStore.removeField(t),this.context.form.removeValidateEventListener(this.validate),this.context.form.fieldsStore.removeListener(e.FieldEvent.Updated,this.reRender)},s.prototype.validate=function(e){var t=this.props.for;e.name===t&&(this.context.form.fieldsStore.removeFieldFor(t,this.key),this.emitValidateEvent(e))},s.prototype.reRender=function(e){this.props.for===e&&this.forceUpdate()},s.prototype.render=function(){var e=this.props,n=(e.for,e.show,e.children),r=i(e,["for","show","children"]);return t.createElement("div",d({},r),n)},s.defaultProps={show:"first"},s.contextTypes={form:n.object.isRequired},s.childContextTypes={fieldFeedbacks:n.object.isRequired},s}(a(y)),F=function(e){function o(t,n){var r=e.call(this,t)||this;return r.validate=r.validate.bind(r),r.key=n.fieldFeedbacks.computeFieldFeedbackKey(),r}return r(o,e),o.prototype.componentWillMount=function(){this.context.fieldFeedbacks.addValidateEventListener(this.validate)},o.prototype.componentWillUnmount=function(){this.context.fieldFeedbacks.removeValidateEventListener(this.validate)},o.prototype.validate=function(e){var t=this.props,n=t.when,r=t.warning,i=t.info,o=this.context.fieldFeedbacks.props.for,s=!1;if("function"==typeof n)n(e.value)&&(s=!0);else{if("string"!=typeof n)throw new TypeError("Invalid FieldFeedback 'when' type: "+typeof n);var a=e.validity;a.valid||("*"===n?s=!0:(a.badInput&&"badInput"===n||a.patternMismatch&&"patternMismatch"===n||a.rangeOverflow&&"rangeOverflow"===n||a.rangeUnderflow&&"rangeUnderflow"===n||a.stepMismatch&&"stepMismatch"===n||a.tooLong&&"tooLong"===n||a.tooShort&&"tooShort"===n||a.typeMismatch&&"typeMismatch"===n||a.valueMissing&&"valueMissing"===n)&&(s=!0))}var l=this.context.form.fieldsStore.cloneField(o);l.dirty=!0,l.validationMessage=e.validationMessage,s&&(r?l.warnings.add(this.key):i?l.infos.add(this.key):l.errors.add(this.key)),this.context.form.fieldsStore.updateField(o,l)},o.prototype.render=function(){var e,n=this.props,r=(n.when,n.error,n.warning,n.info,n.className),o=n.children,s=i(n,["when","error","warning","info","className","children"]),a=this.context.fieldFeedbacks.props,l=a.for,f=a.show,c=this.context.form.fieldsStore.getFieldFor(l,this.context.fieldFeedbacks.key),p=c.errors,u=c.warnings,h=c.infos,v=c.validationMessage,y=p.values().next().value,m=u.values().next().value;p.has(this.key)&&("all"===f||"first"===f&&y===this.key)?e="error":u.has(this.key)&&0===p.size&&("all"===f||"first"===f&&m===this.key)?e="warning":h.has(this.key)&&(e="info");var F=null;return void 0!==e&&(e=void 0!==r?r+" "+e:e,F=void 0!==o?o:v),null!==F?t.createElement("div",d({},s,{className:e}),F):null},o.contextTypes={form:n.object.isRequired,fieldFeedbacks:n.object.isRequired},o}(t.Component);e.fieldWithoutFeedback=p,e.FormWithConstraintsComponent=h,e.FormWithConstraints=v,e.FieldFeedbacksComponent=y,e.FieldFeedbacks=m,e.FieldFeedback=F,e.FieldsStore=u,e.EventEmitter=f,e.ValidateEvent=c,e.withValidateEventEmitter=a,Object.defineProperty(e,"__esModule",{value:!0})}); | ||
//# sourceMappingURL=react-form-with-constraints.production.min.js.map |
@@ -11,4 +11,4 @@ enum Color { | ||
const colors = Object.keys(Color); | ||
const colorKeys = Object.keys(Color); | ||
export { Color, colors }; | ||
export { Color, colorKeys }; |
@@ -5,3 +5,3 @@ /// <reference types="react" /> | ||
import { Input, FormWithConstraintsChildContext, FieldFeedbacksProps } from './index'; | ||
export interface FormGroupProps extends React.AllHTMLAttributes<HTMLDivElement> { | ||
export interface FormGroupProps extends React.HTMLAttributes<HTMLDivElement> { | ||
for?: string; | ||
@@ -21,7 +21,7 @@ } | ||
} | ||
export interface FormControlLabelProps extends React.AllHTMLAttributes<HTMLLabelElement> { | ||
export interface FormControlLabelProps extends React.LabelHTMLAttributes<HTMLLabelElement> { | ||
} | ||
declare const FormControlLabel: React.SFC<FormControlLabelProps>; | ||
export { FormControlLabel }; | ||
export interface FormControlInputProps extends React.AllHTMLAttributes<HTMLInputElement> { | ||
export interface FormControlInputProps extends React.InputHTMLAttributes<HTMLInputElement> { | ||
innerRef?: React.Ref<HTMLInputElement>; | ||
@@ -43,3 +43,3 @@ } | ||
export { FieldFeedbacks }; | ||
export interface LabelWithFormControlStyleProps extends React.AllHTMLAttributes<HTMLLabelElement> { | ||
export interface LabelWithFormControlStyleProps extends React.LabelHTMLAttributes<HTMLLabelElement> { | ||
for: string[]; | ||
@@ -46,0 +46,0 @@ } |
@@ -194,3 +194,3 @@ "use strict"; | ||
var styles = style !== undefined ? __assign({ color: color }, style) : { color: color }; | ||
return (React.createElement("label", __assign({}, labelProps, { style: { styles: styles } }), children)); | ||
return (React.createElement("label", __assign({}, labelProps, { style: styles }), children)); | ||
var _b, _c, _d; | ||
@@ -197,0 +197,0 @@ }; |
@@ -34,3 +34,4 @@ "use strict"; | ||
var _a = input.props(), name = _a.name, value = _a.value; | ||
var fieldFeedbackList = findFieldFeedbackList(input.parent(), name); | ||
// FIXME parent() not listing children with Enzyme 3, see https://github.com/airbnb/enzyme/issues/1235#issuecomment-335053965 | ||
var fieldFeedbackList = findFieldFeedbackList(input.parents(), name); | ||
fieldFeedbackList.forEach(function (fieldFeedback) { | ||
@@ -56,3 +57,3 @@ var _a = fieldFeedback.props(), when = _a.when, children = _a.children; | ||
else { | ||
console.assert(false, "Invalid FieldFeedback 'when': " + when); | ||
throw new TypeError("Invalid FieldFeedback 'when' type: " + typeof when); | ||
} | ||
@@ -121,3 +122,3 @@ }); | ||
default: | ||
console.assert(false, "Invalid FieldFeedback 'when': " + when); | ||
throw new Error("Invalid FieldFeedback 'when' value: " + when); | ||
} | ||
@@ -124,0 +125,0 @@ return validationMessage; |
@@ -13,3 +13,3 @@ /// <reference types="react" /> | ||
export declare type When = WhenString | WhenFn; | ||
export interface FieldFeedbackProps extends React.AllHTMLAttributes<HTMLDivElement> { | ||
export interface FieldFeedbackProps extends React.HTMLAttributes<HTMLDivElement> { | ||
when: When; | ||
@@ -16,0 +16,0 @@ error?: boolean; |
@@ -77,3 +77,3 @@ "use strict"; | ||
else { | ||
console.assert(false, "Invalid FieldFeedback 'when': " + when); | ||
throw new TypeError("Invalid FieldFeedback 'when' type: " + typeof when); | ||
} | ||
@@ -80,0 +80,0 @@ // Update the Fields structure |
@@ -8,3 +8,3 @@ /// <reference types="react" /> | ||
import Input from './Input'; | ||
export interface FieldFeedbacksProps extends React.AllHTMLAttributes<HTMLDivElement> { | ||
export interface FieldFeedbacksProps extends React.HTMLAttributes<HTMLDivElement> { | ||
for: string; | ||
@@ -11,0 +11,0 @@ /** |
@@ -11,3 +11,3 @@ /// <reference types="react" /> | ||
} | ||
export interface FormWithConstraintsProps extends React.AllHTMLAttributes<HTMLFormElement> { | ||
export interface FormWithConstraintsProps extends React.FormHTMLAttributes<HTMLFormElement> { | ||
} | ||
@@ -14,0 +14,0 @@ export interface IFormWithConstraints extends IValidateEventEmitter { |
{ | ||
"name": "react-form-with-constraints", | ||
"version": "0.6.1", | ||
"version": "0.6.2", | ||
"repository": { | ||
@@ -19,4 +19,4 @@ "type": "git", | ||
"build": "webpack -d || true", | ||
"build:watch": "webpack -d --watch", | ||
"build": "cross-env NODE_ENV=development webpack -d || true", | ||
"build:watch": "cross-env NODE_ENV=development webpack -d --watch", | ||
@@ -35,12 +35,2 @@ "tsc:lib": "tsc --project tsconfig.lib.json || true", | ||
"jest": { | ||
"transform": { | ||
"^.+\\.tsx?$": "<rootDir>/node_modules/ts-jest/preprocessor.js" | ||
}, | ||
"testRegex": "(/__tests__/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$", | ||
"moduleFileExtensions": ["ts", "tsx", "js", "jsx", "json"], | ||
"mapCoverage": true | ||
}, | ||
"peerDependencies": { | ||
@@ -52,3 +42,3 @@ "react": ">=15", | ||
"dependencies": { | ||
"prop-types": "^15.6.0", | ||
"prop-types": "latest", | ||
"@types/prop-types": "latest" | ||
@@ -62,5 +52,5 @@ }, | ||
"react": "^15.6.2", | ||
"react": "latest", | ||
"@types/react": "latest", | ||
"react-dom": "^15.6.2", | ||
"react-dom": "latest", | ||
"@types/react-dom": "latest", | ||
@@ -90,3 +80,3 @@ | ||
"rollup-pluginutils": "latest", | ||
"rollup-plugin-typescript2": "ezolenko/rollup-plugin-typescript2", | ||
"rollup-plugin-typescript2": "latest", | ||
"rollup-plugin-uglify": "latest", | ||
@@ -103,6 +93,8 @@ "rollup-plugin-gzip": "latest", | ||
"enzyme": "^2.9.1", | ||
"enzyme": "latest", | ||
"@types/enzyme": "latest", | ||
"react-test-renderer": "^15.6.2" | ||
"enzyme-adapter-react-16": "latest", | ||
"@types/enzyme-adapter-react-16": "latest", | ||
"react-test-renderer": "latest" | ||
} | ||
} |
@@ -68,2 +68,14 @@ # react-form-with-constraints | ||
## Examples | ||
- CodePen basic example: https://codepen.io/tkrotoff/pen/BRGdqL | ||
- CodeSandbox Bootstrap 4 example: https://codesandbox.io/s/qk0zro1qm4 | ||
- CodeSandbox WizardForm example: https://codesandbox.io/s/my0ojyzq6p | ||
- CodeSandbox SignUp example: https://codesandbox.io/s/62qwozvm0k | ||
- CodeSandbox ClubMembers example: https://codesandbox.io/s/q8364yn60j | ||
![example-password](doc/example-password.png) | ||
Other examples inside [the examples directory](examples). | ||
## How it works | ||
@@ -86,14 +98,2 @@ | ||
## Examples | ||
- CodePen basic example: https://codepen.io/tkrotoff/pen/BRGdqL | ||
- CodeSandbox Bootstrap 4 example: https://codesandbox.io/s/qk0zro1qm4 | ||
- CodeSandbox WizardForm example: https://codesandbox.io/s/my0ojyzq6p | ||
- CodeSandbox SignUp example: https://codesandbox.io/s/62qwozvm0k | ||
- CodeSandbox ClubMembers example: https://codesandbox.io/s/q8364yn60j | ||
![example-password](doc/example-password.png) | ||
Other examples inside [the examples directory](examples). | ||
## API | ||
@@ -110,6 +110,8 @@ | ||
for field "password" | ||
when constraint violation "valueMissing" display "the HTML5 error message" | ||
when constraint violation "valueMissing" display "the HTML5 error message (*)" | ||
when constraint violation "patternMismatch" display "Should be at least 5 characters long" | ||
``` | ||
(*) [element.validationMessage](https://www.w3.org/TR/html51/sec-forms.html#the-constraint-validation-api) | ||
- `FieldFeedbacks` | ||
@@ -126,3 +128,2 @@ - `for: string` => refer to a `name` attribute (e.g `<input name="username">`), should be unique to the current form | ||
- `info?: boolean` => treat the feedback as an info | ||
- `children?: ReactNode` => a React node or the HTML5 error message if `undefined` | ||
@@ -177,1 +178,2 @@ - `FormWithConstraints` | ||
- A [`readonly`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#attr-readonly) or `disabled` input won't trigger any HTML5 form constraint like [`required`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#attr-required). | ||
- With `<input type="number">` it's better to use `onInput` instead of `onChange`, see https://github.com/facebook/react/issues/11142 |
@@ -43,3 +43,4 @@ import * as React from 'react'; | ||
const fieldFeedbackList = findFieldFeedbackList(input.parent(), name!); | ||
// FIXME parent() not listing children with Enzyme 3, see https://github.com/airbnb/enzyme/issues/1235#issuecomment-335053965 | ||
const fieldFeedbackList = findFieldFeedbackList(input.parents(), name!); | ||
fieldFeedbackList.forEach(fieldFeedback => { | ||
@@ -67,3 +68,3 @@ const { when, children } = fieldFeedback.props(); | ||
else { | ||
console.assert(false, `Invalid FieldFeedback 'when': ${when}`); | ||
throw new TypeError(`Invalid FieldFeedback 'when' type: ${typeof when}`); | ||
} | ||
@@ -79,3 +80,3 @@ }); | ||
// See https://github.com/MrSwitch/jquery.form.js/blob/48e576db6c0114fe997ac549d074f87be06f54f3/src/jquery.checkValidity.js | ||
function simulateHTML5InputValidation(input: React.HTMLAttributes<HTMLInputElement>, when: string) { | ||
function simulateHTML5InputValidation(input: React.InputHTMLAttributes<HTMLInputElement>, when: string) { | ||
// input.validationMessage | ||
@@ -127,3 +128,3 @@ // See https://developer.mozilla.org/en/docs/Web/API/HTMLInputElement | ||
default: | ||
console.assert(false, `Invalid FieldFeedback 'when': ${when}`); | ||
throw new Error(`Invalid FieldFeedback 'when' value: ${when}`); | ||
} | ||
@@ -130,0 +131,0 @@ |
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
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
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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
644140
173
6918
175
38
Updatedprop-types@latest