-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathreact-input-handler.umd.js
More file actions
2 lines (2 loc) · 1.71 KB
/
react-input-handler.umd.js
File metadata and controls
2 lines (2 loc) · 1.71 KB
1
2
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t(require("lodash.set")):"function"==typeof define&&define.amd?define(["lodash.set"],t):e.ReactInputHandler=t(e.set)}(this,function(e){"use strict";e=e&&e.hasOwnProperty("default")?e.default:e;var t="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},n=function(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e},r=function(e){if(Array.isArray(e)){for(var t=0,n=Array(e.length);t<e.length;t++)n[t]=e[t];return n}return Array.from(e)};function o(e){switch(e.type){case"checkbox":return e.checked;case"select-multiple":return[].concat(r(e.querySelectorAll(":checked"))).map(function(e){return e.value});default:return e.value}}return function(r,u){if(!r)throw new Error("event must be defined");if("object"!==(void 0===r?"undefined":t(r)))throw new Error("event must be an object");if("function"!=typeof this.setState)throw new Error("react-input-handler must be bound to the component instance");if(void 0!==u&&"function"!=typeof u)throw new Error("the 2nd argument of react-input-handler must be a function");var i=r.target,f=i.name;if(!f)throw new Error("all input must have a name prop");if("[]"===f.substr(-2)){var a=f.substr(0,f.length-2),c=o(i),s=this.state[a]||[],l=i.value;if(c)-1===s.indexOf(l)&&this.setState(function(e){return n({},a,s.concat(l))});else{var d=s.indexOf(l);d>-1&&s.splice(d,1),this.setState(function(t){return e(t,a,s)},u)}}else this.setState(function(t){return e(t,f,o(i))},u)}});
//# sourceMappingURL=react-input-handler.umd.js.map