Comparing version 1.0.0 to 1.0.1
@@ -1,1 +0,1 @@ | ||
'use strict';Object.defineProperty(exports,"__esModule",{value:true});var _extends=Object.assign||function(target){for(var i=1;i<arguments.length;i++){var source=arguments[i];for(var key in source){if(Object.prototype.hasOwnProperty.call(source,key)){target[key]=source[key];}}}return target;};var _createClass=function(){function defineProperties(target,props){for(var i=0;i<props.length;i++){var descriptor=props[i];descriptor.enumerable=descriptor.enumerable||false;descriptor.configurable=true;if("value"in descriptor)descriptor.writable=true;Object.defineProperty(target,descriptor.key,descriptor);}}return function(Constructor,protoProps,staticProps){if(protoProps)defineProperties(Constructor.prototype,protoProps);if(staticProps)defineProperties(Constructor,staticProps);return Constructor;};}();var _get=function get(object,property,receiver){if(object===null)object=Function.prototype;var desc=Object.getOwnPropertyDescriptor(object,property);if(desc===undefined){var parent=Object.getPrototypeOf(object);if(parent===null){return undefined;}else{return get(parent,property,receiver);}}else if("value"in desc){return desc.value;}else{var getter=desc.get;if(getter===undefined){return undefined;}return getter.call(receiver);}};var _lodash=require('lodash.clonedeep');var _lodash2=_interopRequireDefault(_lodash);var _lodash3=require('lodash.isequal');var _lodash4=_interopRequireDefault(_lodash3);var _lodash5=require('lodash.set');var _lodash6=_interopRequireDefault(_lodash5);var _react=require('react');var _BaseForm=require('./BaseForm');var _BaseForm2=_interopRequireDefault(_BaseForm);function _interopRequireDefault(obj){return obj&&obj.__esModule?obj:{default:obj};}function _objectWithoutProperties(obj,keys){var target={};for(var i in obj){if(keys.indexOf(i)>=0)continue;if(!Object.prototype.hasOwnProperty.call(obj,i))continue;target[i]=obj[i];}return target;}function _classCallCheck(instance,Constructor){if(!(instance instanceof Constructor)){throw new TypeError("Cannot call a class as a function");}}function _possibleConstructorReturn(self,call){if(!self){throw new ReferenceError("this hasn't been initialised - super() hasn't been called");}return call&&(typeof call==="object"||typeof call==="function")?call:self;}function _inherits(subClass,superClass){if(typeof superClass!=="function"&&superClass!==null){throw new TypeError("Super expression must either be null or a function, not "+typeof superClass);}subClass.prototype=Object.create(superClass&&superClass.prototype,{constructor:{value:subClass,enumerable:false,writable:true,configurable:true}});if(superClass)Object.setPrototypeOf?Object.setPrototypeOf(subClass,superClass):subClass.__proto__=superClass;}var Validated=function Validated(parent){var _class,_temp;return _temp=_class=function(_parent){_inherits(_class,_parent);function _class(){_classCallCheck(this,_class);var _this=_possibleConstructorReturn(this,(_class.__proto__||Object.getPrototypeOf(_class)).apply(this,arguments));_this.state=_extends({},_this.state,{error:null,validate:false,validator:_this.getChildContextSchema().getValidator(_this.props.validator)});_this.onValidate=_this.validate=_this.onValidate.bind(_this);_this.onValidateModel=_this.validateModel=_this.onValidateModel.bind(_this);return _this;}_createClass(_class,[{key:'getChildContextError',value:function getChildContextError(){return _get(_class.prototype.__proto__||Object.getPrototypeOf(_class.prototype),'getChildContextError',this).call(this)||this.state.error;}},{key:'getNativeFormProps',value:function getNativeFormProps(){var _get$call=_get(_class.prototype.__proto__||Object.getPrototypeOf(_class.prototype),'getNativeFormProps',this).call(this);var onValidate=_get$call.onValidate;var validator=_get$call.validator;var validate=_get$call.validate;var props=_objectWithoutProperties(_get$call,['onValidate','validator','validate']);return props;}},{key:'componentWillReceiveProps',value:function componentWillReceiveProps(_ref){var _this2=this;var model=_ref.model;var schema=_ref.schema;var validate=_ref.validate;var validator=_ref.validator;_get(_class.prototype.__proto__||Object.getPrototypeOf(_class.prototype),'componentWillReceiveProps',this).apply(this,arguments);if(this.props.schema!==schema||this.props.validator!==validator){this.setState({validator:this.getChildContextSchema().getValidator(validator)},function(){if(validate==='onChange'||validate==='onChangeAfterSubmit'&&_this2.state.validate){_this2.onValidate();}});}else if(!(0,_lodash4.default)(this.props.model,model)){if(validate==='onChange'||validate==='onChangeAfterSubmit'&&this.state.validate){this.onValidate();}}}},{key:'onChange',value:function onChange(key,value){if(this.props.validate==='onChange'||this.props.validate==='onChangeAfterSubmit'&&this.state.validate){this.onValidate(key,value);}_get(_class.prototype.__proto__||Object.getPrototypeOf(_class.prototype),'onChange',this).apply(this,arguments);}},{key:'onReset',value:function onReset(){_get(_class.prototype.__proto__||Object.getPrototypeOf(_class.prototype),'onReset',this).call(this);this.setState(function(){return{error:null,validate:false};});}},{key:'onSubmit',value:function onSubmit(event){var _this3=this;if(event){event.preventDefault();event.stopPropagation();}return new Promise(function(resolve){return _this3.setState({validate:true},function(){return resolve(_this3.onValidate().then(function(){return _get(_class.prototype.__proto__||Object.getPrototypeOf(_class.prototype),'onSubmit',_this3).call(_this3);}));});});}},{key:'onValidate',value:function onValidate(key,value){var model=this.getModel();if(model&&key){model=(0,_lodash6.default)((0,_lodash2.default)(model),key,(0,_lodash2.default)(value));}return this.onValidateModel(model);}},{key:'onValidateModel',value:function onValidateModel(model){var _this4=this;var catched=this.props.error||null;try{this.state.validator(model);}catch(error){catched=error;}var markAndHandle=function markAndHandle(){var error=arguments.length<=0||arguments[0]===undefined?catched:arguments[0];var resolve=arguments[1];var reject=arguments[2];return _this4.setState({error:error},function(){if(error){error.__uniformsPromiseMark=true;reject(error);}else{resolve();}});};return new Promise(function(resolve,reject){return _this4.props.onValidate?_this4.props.onValidate(model,catched,function(error){return markAndHandle(error,resolve,reject);}):markAndHandle(catched,resolve,reject);});}}]);return _class;}(parent),_class.Validated=Validated,_class.displayName='Validated'+parent.displayName,_class.defaultProps=_extends({},parent.defaultProps,{validate:'onChangeAfterSubmit'}),_class.propTypes=_extends({},parent.propTypes,{onValidate:_react.PropTypes.func,validator:_react.PropTypes.any,validate:_react.PropTypes.oneOf(['onChange','onChangeAfterSubmit','onSubmit'])}),_temp;};exports.default=Validated(_BaseForm2.default); | ||
'use strict';Object.defineProperty(exports,"__esModule",{value:true});var _extends=Object.assign||function(target){for(var i=1;i<arguments.length;i++){var source=arguments[i];for(var key in source){if(Object.prototype.hasOwnProperty.call(source,key)){target[key]=source[key];}}}return target;};var _createClass=function(){function defineProperties(target,props){for(var i=0;i<props.length;i++){var descriptor=props[i];descriptor.enumerable=descriptor.enumerable||false;descriptor.configurable=true;if("value"in descriptor)descriptor.writable=true;Object.defineProperty(target,descriptor.key,descriptor);}}return function(Constructor,protoProps,staticProps){if(protoProps)defineProperties(Constructor.prototype,protoProps);if(staticProps)defineProperties(Constructor,staticProps);return Constructor;};}();var _get=function get(object,property,receiver){if(object===null)object=Function.prototype;var desc=Object.getOwnPropertyDescriptor(object,property);if(desc===undefined){var parent=Object.getPrototypeOf(object);if(parent===null){return undefined;}else{return get(parent,property,receiver);}}else if("value"in desc){return desc.value;}else{var getter=desc.get;if(getter===undefined){return undefined;}return getter.call(receiver);}};var _lodash=require('lodash.clonedeep');var _lodash2=_interopRequireDefault(_lodash);var _lodash3=require('lodash.isequal');var _lodash4=_interopRequireDefault(_lodash3);var _lodash5=require('lodash.set');var _lodash6=_interopRequireDefault(_lodash5);var _react=require('react');var _BaseForm=require('./BaseForm');var _BaseForm2=_interopRequireDefault(_BaseForm);function _interopRequireDefault(obj){return obj&&obj.__esModule?obj:{default:obj};}function _objectWithoutProperties(obj,keys){var target={};for(var i in obj){if(keys.indexOf(i)>=0)continue;if(!Object.prototype.hasOwnProperty.call(obj,i))continue;target[i]=obj[i];}return target;}function _classCallCheck(instance,Constructor){if(!(instance instanceof Constructor)){throw new TypeError("Cannot call a class as a function");}}function _possibleConstructorReturn(self,call){if(!self){throw new ReferenceError("this hasn't been initialised - super() hasn't been called");}return call&&(typeof call==="object"||typeof call==="function")?call:self;}function _inherits(subClass,superClass){if(typeof superClass!=="function"&&superClass!==null){throw new TypeError("Super expression must either be null or a function, not "+typeof superClass);}subClass.prototype=Object.create(superClass&&superClass.prototype,{constructor:{value:subClass,enumerable:false,writable:true,configurable:true}});if(superClass)Object.setPrototypeOf?Object.setPrototypeOf(subClass,superClass):subClass.__proto__=superClass;}var Validated=function Validated(parent){var _class,_temp;return _temp=_class=function(_parent){_inherits(_class,_parent);function _class(){_classCallCheck(this,_class);var _this=_possibleConstructorReturn(this,(_class.__proto__||Object.getPrototypeOf(_class)).apply(this,arguments));_this.state=_extends({},_this.state,{error:null,validate:false,validator:_this.getChildContextSchema().getValidator(_this.props.validator)});_this.onValidate=_this.validate=_this.onValidate.bind(_this);_this.onValidateModel=_this.validateModel=_this.onValidateModel.bind(_this);return _this;}_createClass(_class,[{key:'getChildContextError',value:function getChildContextError(){return _get(_class.prototype.__proto__||Object.getPrototypeOf(_class.prototype),'getChildContextError',this).call(this)||this.state.error;}},{key:'getNativeFormProps',value:function getNativeFormProps(){var _get$call=_get(_class.prototype.__proto__||Object.getPrototypeOf(_class.prototype),'getNativeFormProps',this).call(this);var onValidate=_get$call.onValidate;var validator=_get$call.validator;var validate=_get$call.validate;var props=_objectWithoutProperties(_get$call,['onValidate','validator','validate']);return props;}},{key:'componentWillReceiveProps',value:function componentWillReceiveProps(_ref){var _this2=this;var model=_ref.model;var schema=_ref.schema;var validate=_ref.validate;var validator=_ref.validator;_get(_class.prototype.__proto__||Object.getPrototypeOf(_class.prototype),'componentWillReceiveProps',this).apply(this,arguments);if(this.props.schema!==schema||this.props.validator!==validator){this.setState({validator:this.getChildContextSchema().getValidator(validator)},function(){if(validate==='onChange'||validate==='onChangeAfterSubmit'&&_this2.state.validate){_this2.onValidate();}});}else if(!(0,_lodash4.default)(this.props.model,model)){if(validate==='onChange'||validate==='onChangeAfterSubmit'&&this.state.validate){this.onValidateModel(model);}}}},{key:'onChange',value:function onChange(key,value){if(this.props.validate==='onChange'||this.props.validate==='onChangeAfterSubmit'&&this.state.validate){this.onValidate(key,value);}_get(_class.prototype.__proto__||Object.getPrototypeOf(_class.prototype),'onChange',this).apply(this,arguments);}},{key:'onReset',value:function onReset(){_get(_class.prototype.__proto__||Object.getPrototypeOf(_class.prototype),'onReset',this).call(this);this.setState(function(){return{error:null,validate:false};});}},{key:'onSubmit',value:function onSubmit(event){var _this3=this;if(event){event.preventDefault();event.stopPropagation();}return new Promise(function(resolve){return _this3.setState({validate:true},function(){return resolve(_this3.onValidate().then(function(){return _get(_class.prototype.__proto__||Object.getPrototypeOf(_class.prototype),'onSubmit',_this3).call(_this3);}));});});}},{key:'onValidate',value:function onValidate(key,value){var model=this.getModel();if(model&&key){model=(0,_lodash6.default)((0,_lodash2.default)(model),key,(0,_lodash2.default)(value));}return this.onValidateModel(model);}},{key:'onValidateModel',value:function onValidateModel(model){var _this4=this;var catched=this.props.error||null;try{this.state.validator(model);}catch(error){catched=error;}var markAndHandle=function markAndHandle(){var error=arguments.length<=0||arguments[0]===undefined?catched:arguments[0];var resolve=arguments[1];var reject=arguments[2];return _this4.setState({error:error},function(){if(error){error.__uniformsPromiseMark=true;reject(error);}else{resolve();}});};return new Promise(function(resolve,reject){return _this4.props.onValidate?_this4.props.onValidate(model,catched,function(error){return markAndHandle(error,resolve,reject);}):markAndHandle(catched,resolve,reject);});}}]);return _class;}(parent),_class.Validated=Validated,_class.displayName='Validated'+parent.displayName,_class.defaultProps=_extends({},parent.defaultProps,{validate:'onChangeAfterSubmit'}),_class.propTypes=_extends({},parent.propTypes,{onValidate:_react.PropTypes.func,validator:_react.PropTypes.any,validate:_react.PropTypes.oneOf(['onChange','onChangeAfterSubmit','onSubmit'])}),_temp;};exports.default=Validated(_BaseForm2.default); |
{ | ||
"name": "uniforms", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"main": "lib/index.js", | ||
@@ -5,0 +5,0 @@ "jsnext:main": "src/index.js", |
@@ -83,3 +83,3 @@ import cloneDeep from 'lodash.clonedeep'; | ||
validate === 'onChangeAfterSubmit' && this.state.validate) { | ||
this.onValidate(); | ||
this.onValidateModel(model); | ||
} | ||
@@ -86,0 +86,0 @@ } |
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
100824