easy-react-form
Advanced tools
Comparing version 1.0.19 to 1.0.20
@@ -74,5 +74,3 @@ 'use strict'; | ||
}, | ||
// These're used by `<List/>` (plus `.fields`). | ||
resetField: _this.resetField, | ||
cleanUpRemovedFields: _this.cleanUpRemovedFields, | ||
// These're used by `<List/>`. | ||
focus: _this.focus, | ||
@@ -89,2 +87,20 @@ getValues: _this.values, | ||
}); | ||
for (var _iterator = _this.plugins, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) { | ||
var _ref; | ||
if (_isArray) { | ||
if (_i >= _iterator.length) break; | ||
_ref = _iterator[_i++]; | ||
} else { | ||
_i = _iterator.next(); | ||
if (_i.done) break; | ||
_ref = _i.value; | ||
} | ||
var plugin = _ref; | ||
if (plugin.initContext) { | ||
plugin.initContext(_this.state); | ||
} | ||
} | ||
return _this; | ||
@@ -113,15 +129,15 @@ } | ||
for (var _iterator = this.plugins, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) { | ||
var _ref; | ||
for (var _iterator2 = this.plugins, _isArray2 = Array.isArray(_iterator2), _i2 = 0, _iterator2 = _isArray2 ? _iterator2 : _iterator2[Symbol.iterator]();;) { | ||
var _ref2; | ||
if (_isArray) { | ||
if (_i >= _iterator.length) break; | ||
_ref = _iterator[_i++]; | ||
if (_isArray2) { | ||
if (_i2 >= _iterator2.length) break; | ||
_ref2 = _iterator2[_i2++]; | ||
} else { | ||
_i = _iterator.next(); | ||
if (_i.done) break; | ||
_ref = _i.value; | ||
_i2 = _iterator2.next(); | ||
if (_i2.done) break; | ||
_ref2 = _i2.value; | ||
} | ||
var plugin = _ref; | ||
var plugin = _ref2; | ||
@@ -146,15 +162,15 @@ if (plugin.onMount) { | ||
value: function componentWillUnmount() { | ||
for (var _iterator2 = this.plugins, _isArray2 = Array.isArray(_iterator2), _i2 = 0, _iterator2 = _isArray2 ? _iterator2 : _iterator2[Symbol.iterator]();;) { | ||
var _ref2; | ||
for (var _iterator3 = this.plugins, _isArray3 = Array.isArray(_iterator3), _i3 = 0, _iterator3 = _isArray3 ? _iterator3 : _iterator3[Symbol.iterator]();;) { | ||
var _ref3; | ||
if (_isArray2) { | ||
if (_i2 >= _iterator2.length) break; | ||
_ref2 = _iterator2[_i2++]; | ||
if (_isArray3) { | ||
if (_i3 >= _iterator3.length) break; | ||
_ref3 = _iterator3[_i3++]; | ||
} else { | ||
_i2 = _iterator2.next(); | ||
if (_i2.done) break; | ||
_ref2 = _i2.value; | ||
_i3 = _iterator3.next(); | ||
if (_i3.done) break; | ||
_ref3 = _i3.value; | ||
} | ||
var plugin = _ref2; | ||
var plugin = _ref3; | ||
@@ -199,15 +215,15 @@ if (plugin.onUnmount) { | ||
for (var _iterator3 = Object.keys(fields), _isArray3 = Array.isArray(_iterator3), _i3 = 0, _iterator3 = _isArray3 ? _iterator3 : _iterator3[Symbol.iterator]();;) { | ||
var _ref3; | ||
for (var _iterator4 = Object.keys(fields), _isArray4 = Array.isArray(_iterator4), _i4 = 0, _iterator4 = _isArray4 ? _iterator4 : _iterator4[Symbol.iterator]();;) { | ||
var _ref4; | ||
if (_isArray3) { | ||
if (_i3 >= _iterator3.length) break; | ||
_ref3 = _iterator3[_i3++]; | ||
if (_isArray4) { | ||
if (_i4 >= _iterator4.length) break; | ||
_ref4 = _iterator4[_i4++]; | ||
} else { | ||
_i3 = _iterator3.next(); | ||
if (_i3.done) break; | ||
_ref3 = _i3.value; | ||
_i4 = _iterator4.next(); | ||
if (_i4.done) break; | ||
_ref4 = _i4.value; | ||
} | ||
var field = _ref3; | ||
var field = _ref4; | ||
@@ -246,15 +262,15 @@ // If the field is not mounted then ignore it. | ||
// all required ones which are not filled. | ||
for (var _iterator4 = Object.keys(fields), _isArray4 = Array.isArray(_iterator4), _i4 = 0, _iterator4 = _isArray4 ? _iterator4 : _iterator4[Symbol.iterator]();;) { | ||
var _ref4; | ||
for (var _iterator5 = Object.keys(fields), _isArray5 = Array.isArray(_iterator5), _i5 = 0, _iterator5 = _isArray5 ? _iterator5 : _iterator5[Symbol.iterator]();;) { | ||
var _ref5; | ||
if (_isArray4) { | ||
if (_i4 >= _iterator4.length) break; | ||
_ref4 = _iterator4[_i4++]; | ||
if (_isArray5) { | ||
if (_i5 >= _iterator5.length) break; | ||
_ref5 = _iterator5[_i5++]; | ||
} else { | ||
_i4 = _iterator4.next(); | ||
if (_i4.done) break; | ||
_ref4 = _i4.value; | ||
_i5 = _iterator5.next(); | ||
if (_i5.done) break; | ||
_ref5 = _i5.value; | ||
} | ||
var _field = _ref4; | ||
var _field = _ref5; | ||
@@ -512,15 +528,15 @@ // Trigger `validate()` on the field | ||
for (var _iterator5 = _this4.plugins, _isArray5 = Array.isArray(_iterator5), _i5 = 0, _iterator5 = _isArray5 ? _iterator5 : _iterator5[Symbol.iterator]();;) { | ||
var _ref5; | ||
for (var _iterator6 = _this4.plugins, _isArray6 = Array.isArray(_iterator6), _i6 = 0, _iterator6 = _isArray6 ? _iterator6 : _iterator6[Symbol.iterator]();;) { | ||
var _ref6; | ||
if (_isArray5) { | ||
if (_i5 >= _iterator5.length) break; | ||
_ref5 = _iterator5[_i5++]; | ||
if (_isArray6) { | ||
if (_i6 >= _iterator6.length) break; | ||
_ref6 = _iterator6[_i6++]; | ||
} else { | ||
_i5 = _iterator5.next(); | ||
if (_i5.done) break; | ||
_ref5 = _i5.value; | ||
_i6 = _iterator6.next(); | ||
if (_i6.done) break; | ||
_ref6 = _i6.value; | ||
} | ||
var plugin = _ref5; | ||
var plugin = _ref6; | ||
@@ -543,15 +559,15 @@ if (plugin.getValue) { | ||
var _values = (0, _utility.getValues)(customValues || values, fields); | ||
for (var _iterator6 = _this4.plugins, _isArray6 = Array.isArray(_iterator6), _i6 = 0, _iterator6 = _isArray6 ? _iterator6 : _iterator6[Symbol.iterator]();;) { | ||
var _ref6; | ||
for (var _iterator7 = _this4.plugins, _isArray7 = Array.isArray(_iterator7), _i7 = 0, _iterator7 = _isArray7 ? _iterator7 : _iterator7[Symbol.iterator]();;) { | ||
var _ref7; | ||
if (_isArray6) { | ||
if (_i6 >= _iterator6.length) break; | ||
_ref6 = _iterator6[_i6++]; | ||
if (_isArray7) { | ||
if (_i7 >= _iterator7.length) break; | ||
_ref7 = _iterator7[_i7++]; | ||
} else { | ||
_i6 = _iterator6.next(); | ||
if (_i6.done) break; | ||
_ref6 = _i6.value; | ||
_i7 = _iterator7.next(); | ||
if (_i7.done) break; | ||
_ref7 = _i7.value; | ||
} | ||
var plugin = _ref6; | ||
var plugin = _ref7; | ||
@@ -575,15 +591,15 @@ if (plugin.getValues) { | ||
for (var _iterator7 = _this4.plugins, _isArray7 = Array.isArray(_iterator7), _i7 = 0, _iterator7 = _isArray7 ? _iterator7 : _iterator7[Symbol.iterator]();;) { | ||
var _ref7; | ||
for (var _iterator8 = _this4.plugins, _isArray8 = Array.isArray(_iterator8), _i8 = 0, _iterator8 = _isArray8 ? _iterator8 : _iterator8[Symbol.iterator]();;) { | ||
var _ref8; | ||
if (_isArray7) { | ||
if (_i7 >= _iterator7.length) break; | ||
_ref7 = _iterator7[_i7++]; | ||
if (_isArray8) { | ||
if (_i8 >= _iterator8.length) break; | ||
_ref8 = _iterator8[_i8++]; | ||
} else { | ||
_i7 = _iterator7.next(); | ||
if (_i7.done) break; | ||
_ref7 = _i7.value; | ||
_i8 = _iterator8.next(); | ||
if (_i8.done) break; | ||
_ref8 = _i8.value; | ||
} | ||
var plugin = _ref7; | ||
var plugin = _ref8; | ||
@@ -611,2 +627,22 @@ if (plugin.onReset) { | ||
this.resetField = function (name) { | ||
for (var _iterator9 = _this4.plugins, _isArray9 = Array.isArray(_iterator9), _i9 = 0, _iterator9 = _isArray9 ? _iterator9 : _iterator9[Symbol.iterator]();;) { | ||
var _ref9; | ||
if (_isArray9) { | ||
if (_i9 >= _iterator9.length) break; | ||
_ref9 = _iterator9[_i9++]; | ||
} else { | ||
_i9 = _iterator9.next(); | ||
if (_i9.done) break; | ||
_ref9 = _i9.value; | ||
} | ||
var plugin = _ref9; | ||
if (plugin.onResetField) { | ||
if (plugin.onResetField(name, form)) { | ||
return; | ||
} | ||
} | ||
} | ||
var initialValue = _this4.fields[name].initialValue === undefined ? _this4.getInitialValue(name) : _this4.fields[name].initialValue; | ||
@@ -626,15 +662,15 @@ _this4.dispatch((0, _actions.setFieldValue)(name, initialValue)); | ||
for (var _iterator8 = Object.keys(fields), _isArray8 = Array.isArray(_iterator8), _i8 = 0, _iterator8 = _isArray8 ? _iterator8 : _iterator8[Symbol.iterator]();;) { | ||
var _ref8; | ||
for (var _iterator10 = Object.keys(fields), _isArray10 = Array.isArray(_iterator10), _i10 = 0, _iterator10 = _isArray10 ? _iterator10 : _iterator10[Symbol.iterator]();;) { | ||
var _ref10; | ||
if (_isArray8) { | ||
if (_i8 >= _iterator8.length) break; | ||
_ref8 = _iterator8[_i8++]; | ||
if (_isArray10) { | ||
if (_i10 >= _iterator10.length) break; | ||
_ref10 = _iterator10[_i10++]; | ||
} else { | ||
_i8 = _iterator8.next(); | ||
if (_i8.done) break; | ||
_ref8 = _i8.value; | ||
_i10 = _iterator10.next(); | ||
if (_i10.done) break; | ||
_ref10 = _i10.value; | ||
} | ||
var field = _ref8; | ||
var field = _ref10; | ||
@@ -651,15 +687,15 @@ // Remove unmounted `<Field/>`s. | ||
for (var _iterator9 = _this4.plugins, _isArray9 = Array.isArray(_iterator9), _i9 = 0, _iterator9 = _isArray9 ? _iterator9 : _iterator9[Symbol.iterator]();;) { | ||
var _ref9; | ||
for (var _iterator11 = _this4.plugins, _isArray11 = Array.isArray(_iterator11), _i11 = 0, _iterator11 = _isArray11 ? _iterator11 : _iterator11[Symbol.iterator]();;) { | ||
var _ref11; | ||
if (_isArray9) { | ||
if (_i9 >= _iterator9.length) break; | ||
_ref9 = _iterator9[_i9++]; | ||
if (_isArray11) { | ||
if (_i11 >= _iterator11.length) break; | ||
_ref11 = _iterator11[_i11++]; | ||
} else { | ||
_i9 = _iterator9.next(); | ||
if (_i9.done) break; | ||
_ref9 = _i9.value; | ||
_i11 = _iterator11.next(); | ||
if (_i11.done) break; | ||
_ref11 = _i11.value; | ||
} | ||
var plugin = _ref9; | ||
var plugin = _ref11; | ||
@@ -817,2 +853,3 @@ if (plugin.onAfterSubmit) { | ||
onUnregisterField: _propTypes2.default.func.isRequired, | ||
onRegisterList: _propTypes2.default.func.isRequired, | ||
focus: _propTypes2.default.isRequired, | ||
@@ -819,0 +856,0 @@ dispatch: _propTypes2.default.func.isRequired, |
@@ -56,2 +56,6 @@ 'use strict'; | ||
_this.onReset = function (callback) { | ||
_this.setState(_this.getInitialItemsState(), callback); | ||
}; | ||
_this.getFieldName = function (i, name) { | ||
@@ -106,28 +110,2 @@ if (typeof i !== 'number') { | ||
_this.reset = function () { | ||
var _this$props = _this.props, | ||
name = _this$props.name, | ||
context = _this$props.context; | ||
for (var _iterator = Object.keys(context.fields), _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) { | ||
var _ref; | ||
if (_isArray) { | ||
if (_i >= _iterator.length) break; | ||
_ref = _iterator[_i++]; | ||
} else { | ||
_i = _iterator.next(); | ||
if (_i.done) break; | ||
_ref = _i.value; | ||
} | ||
var field = _ref; | ||
if (field.indexOf(name + ':') === 0) { | ||
context.resetField(field); | ||
} | ||
} | ||
_this.setState(_this.getInitialItemsState(), context.cleanUpRemovedFields); | ||
}; | ||
_this.state = _extends({ | ||
@@ -143,9 +121,20 @@ context: { | ||
_createClass(List, [{ | ||
key: 'getInitialItems', | ||
value: function getInitialItems() { | ||
key: 'componentDidMount', | ||
value: function componentDidMount() { | ||
var _props = this.props, | ||
context = _props.context, | ||
name = _props.name, | ||
count = _props.count; | ||
context = _props.context; | ||
context.onRegisterList(name, { | ||
onReset: this.onReset | ||
}); | ||
} | ||
}, { | ||
key: 'getInitialItems', | ||
value: function getInitialItems() { | ||
var _props2 = this.props, | ||
context = _props2.context, | ||
name = _props2.name, | ||
count = _props2.count; | ||
if (context.initialValues[name]) { | ||
@@ -165,5 +154,2 @@ return createIndexArray(context.initialValues[name].length); | ||
} | ||
// Hasn't been tested. | ||
}, { | ||
@@ -170,0 +156,0 @@ key: 'render', |
@@ -17,5 +17,20 @@ 'use strict'; | ||
_classCallCheck(this, ListPlugin); | ||
this.lists = {}; | ||
} | ||
// Tracks `<List/>`s. | ||
_createClass(ListPlugin, [{ | ||
key: 'initContext', | ||
value: function initContext(context) { | ||
var _this = this; | ||
context.onRegisterList = function (name, _ref) { | ||
var onReset = _ref.onReset; | ||
_this.lists[name] = { onReset: onReset }; | ||
}; | ||
} | ||
}, { | ||
key: 'getValues', | ||
@@ -32,2 +47,30 @@ value: function getValues(values) { | ||
} | ||
}, { | ||
key: 'onResetField', | ||
value: function onResetField(name, form) { | ||
if (this.lists[name]) { | ||
var fields = form.state.fields; | ||
for (var _iterator = Object.keys(fields), _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) { | ||
var _ref2; | ||
if (_isArray) { | ||
if (_i >= _iterator.length) break; | ||
_ref2 = _iterator[_i++]; | ||
} else { | ||
_i = _iterator.next(); | ||
if (_i.done) break; | ||
_ref2 = _i.value; | ||
} | ||
var field = _ref2; | ||
if (field.indexOf(name + ':') === 0) { | ||
form.resetField(field); | ||
} | ||
} | ||
this.lists[name].onReset(form.cleanUpRemovedFields); | ||
return true; | ||
} | ||
} | ||
}]); | ||
@@ -34,0 +77,0 @@ |
@@ -74,5 +74,3 @@ 'use strict'; | ||
}, | ||
// These're used by `<List/>` (plus `.fields`). | ||
resetField: _this.resetField, | ||
cleanUpRemovedFields: _this.cleanUpRemovedFields, | ||
// These're used by `<List/>`. | ||
focus: _this.focus, | ||
@@ -89,2 +87,20 @@ getValues: _this.values, | ||
}); | ||
for (var _iterator = _this.plugins, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) { | ||
var _ref; | ||
if (_isArray) { | ||
if (_i >= _iterator.length) break; | ||
_ref = _iterator[_i++]; | ||
} else { | ||
_i = _iterator.next(); | ||
if (_i.done) break; | ||
_ref = _i.value; | ||
} | ||
var plugin = _ref; | ||
if (plugin.initContext) { | ||
plugin.initContext(_this.state); | ||
} | ||
} | ||
return _this; | ||
@@ -113,15 +129,15 @@ } | ||
for (var _iterator = this.plugins, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) { | ||
var _ref; | ||
for (var _iterator2 = this.plugins, _isArray2 = Array.isArray(_iterator2), _i2 = 0, _iterator2 = _isArray2 ? _iterator2 : _iterator2[Symbol.iterator]();;) { | ||
var _ref2; | ||
if (_isArray) { | ||
if (_i >= _iterator.length) break; | ||
_ref = _iterator[_i++]; | ||
if (_isArray2) { | ||
if (_i2 >= _iterator2.length) break; | ||
_ref2 = _iterator2[_i2++]; | ||
} else { | ||
_i = _iterator.next(); | ||
if (_i.done) break; | ||
_ref = _i.value; | ||
_i2 = _iterator2.next(); | ||
if (_i2.done) break; | ||
_ref2 = _i2.value; | ||
} | ||
var plugin = _ref; | ||
var plugin = _ref2; | ||
@@ -146,15 +162,15 @@ if (plugin.onMount) { | ||
value: function componentWillUnmount() { | ||
for (var _iterator2 = this.plugins, _isArray2 = Array.isArray(_iterator2), _i2 = 0, _iterator2 = _isArray2 ? _iterator2 : _iterator2[Symbol.iterator]();;) { | ||
var _ref2; | ||
for (var _iterator3 = this.plugins, _isArray3 = Array.isArray(_iterator3), _i3 = 0, _iterator3 = _isArray3 ? _iterator3 : _iterator3[Symbol.iterator]();;) { | ||
var _ref3; | ||
if (_isArray2) { | ||
if (_i2 >= _iterator2.length) break; | ||
_ref2 = _iterator2[_i2++]; | ||
if (_isArray3) { | ||
if (_i3 >= _iterator3.length) break; | ||
_ref3 = _iterator3[_i3++]; | ||
} else { | ||
_i2 = _iterator2.next(); | ||
if (_i2.done) break; | ||
_ref2 = _i2.value; | ||
_i3 = _iterator3.next(); | ||
if (_i3.done) break; | ||
_ref3 = _i3.value; | ||
} | ||
var plugin = _ref2; | ||
var plugin = _ref3; | ||
@@ -199,15 +215,15 @@ if (plugin.onUnmount) { | ||
for (var _iterator3 = Object.keys(fields), _isArray3 = Array.isArray(_iterator3), _i3 = 0, _iterator3 = _isArray3 ? _iterator3 : _iterator3[Symbol.iterator]();;) { | ||
var _ref3; | ||
for (var _iterator4 = Object.keys(fields), _isArray4 = Array.isArray(_iterator4), _i4 = 0, _iterator4 = _isArray4 ? _iterator4 : _iterator4[Symbol.iterator]();;) { | ||
var _ref4; | ||
if (_isArray3) { | ||
if (_i3 >= _iterator3.length) break; | ||
_ref3 = _iterator3[_i3++]; | ||
if (_isArray4) { | ||
if (_i4 >= _iterator4.length) break; | ||
_ref4 = _iterator4[_i4++]; | ||
} else { | ||
_i3 = _iterator3.next(); | ||
if (_i3.done) break; | ||
_ref3 = _i3.value; | ||
_i4 = _iterator4.next(); | ||
if (_i4.done) break; | ||
_ref4 = _i4.value; | ||
} | ||
var field = _ref3; | ||
var field = _ref4; | ||
@@ -246,15 +262,15 @@ // If the field is not mounted then ignore it. | ||
// all required ones which are not filled. | ||
for (var _iterator4 = Object.keys(fields), _isArray4 = Array.isArray(_iterator4), _i4 = 0, _iterator4 = _isArray4 ? _iterator4 : _iterator4[Symbol.iterator]();;) { | ||
var _ref4; | ||
for (var _iterator5 = Object.keys(fields), _isArray5 = Array.isArray(_iterator5), _i5 = 0, _iterator5 = _isArray5 ? _iterator5 : _iterator5[Symbol.iterator]();;) { | ||
var _ref5; | ||
if (_isArray4) { | ||
if (_i4 >= _iterator4.length) break; | ||
_ref4 = _iterator4[_i4++]; | ||
if (_isArray5) { | ||
if (_i5 >= _iterator5.length) break; | ||
_ref5 = _iterator5[_i5++]; | ||
} else { | ||
_i4 = _iterator4.next(); | ||
if (_i4.done) break; | ||
_ref4 = _i4.value; | ||
_i5 = _iterator5.next(); | ||
if (_i5.done) break; | ||
_ref5 = _i5.value; | ||
} | ||
var _field = _ref4; | ||
var _field = _ref5; | ||
@@ -512,15 +528,15 @@ // Trigger `validate()` on the field | ||
for (var _iterator5 = _this4.plugins, _isArray5 = Array.isArray(_iterator5), _i5 = 0, _iterator5 = _isArray5 ? _iterator5 : _iterator5[Symbol.iterator]();;) { | ||
var _ref5; | ||
for (var _iterator6 = _this4.plugins, _isArray6 = Array.isArray(_iterator6), _i6 = 0, _iterator6 = _isArray6 ? _iterator6 : _iterator6[Symbol.iterator]();;) { | ||
var _ref6; | ||
if (_isArray5) { | ||
if (_i5 >= _iterator5.length) break; | ||
_ref5 = _iterator5[_i5++]; | ||
if (_isArray6) { | ||
if (_i6 >= _iterator6.length) break; | ||
_ref6 = _iterator6[_i6++]; | ||
} else { | ||
_i5 = _iterator5.next(); | ||
if (_i5.done) break; | ||
_ref5 = _i5.value; | ||
_i6 = _iterator6.next(); | ||
if (_i6.done) break; | ||
_ref6 = _i6.value; | ||
} | ||
var plugin = _ref5; | ||
var plugin = _ref6; | ||
@@ -543,15 +559,15 @@ if (plugin.getValue) { | ||
var _values = (0, _utility.getValues)(customValues || values, fields); | ||
for (var _iterator6 = _this4.plugins, _isArray6 = Array.isArray(_iterator6), _i6 = 0, _iterator6 = _isArray6 ? _iterator6 : _iterator6[Symbol.iterator]();;) { | ||
var _ref6; | ||
for (var _iterator7 = _this4.plugins, _isArray7 = Array.isArray(_iterator7), _i7 = 0, _iterator7 = _isArray7 ? _iterator7 : _iterator7[Symbol.iterator]();;) { | ||
var _ref7; | ||
if (_isArray6) { | ||
if (_i6 >= _iterator6.length) break; | ||
_ref6 = _iterator6[_i6++]; | ||
if (_isArray7) { | ||
if (_i7 >= _iterator7.length) break; | ||
_ref7 = _iterator7[_i7++]; | ||
} else { | ||
_i6 = _iterator6.next(); | ||
if (_i6.done) break; | ||
_ref6 = _i6.value; | ||
_i7 = _iterator7.next(); | ||
if (_i7.done) break; | ||
_ref7 = _i7.value; | ||
} | ||
var plugin = _ref6; | ||
var plugin = _ref7; | ||
@@ -575,15 +591,15 @@ if (plugin.getValues) { | ||
for (var _iterator7 = _this4.plugins, _isArray7 = Array.isArray(_iterator7), _i7 = 0, _iterator7 = _isArray7 ? _iterator7 : _iterator7[Symbol.iterator]();;) { | ||
var _ref7; | ||
for (var _iterator8 = _this4.plugins, _isArray8 = Array.isArray(_iterator8), _i8 = 0, _iterator8 = _isArray8 ? _iterator8 : _iterator8[Symbol.iterator]();;) { | ||
var _ref8; | ||
if (_isArray7) { | ||
if (_i7 >= _iterator7.length) break; | ||
_ref7 = _iterator7[_i7++]; | ||
if (_isArray8) { | ||
if (_i8 >= _iterator8.length) break; | ||
_ref8 = _iterator8[_i8++]; | ||
} else { | ||
_i7 = _iterator7.next(); | ||
if (_i7.done) break; | ||
_ref7 = _i7.value; | ||
_i8 = _iterator8.next(); | ||
if (_i8.done) break; | ||
_ref8 = _i8.value; | ||
} | ||
var plugin = _ref7; | ||
var plugin = _ref8; | ||
@@ -611,2 +627,22 @@ if (plugin.onReset) { | ||
this.resetField = function (name) { | ||
for (var _iterator9 = _this4.plugins, _isArray9 = Array.isArray(_iterator9), _i9 = 0, _iterator9 = _isArray9 ? _iterator9 : _iterator9[Symbol.iterator]();;) { | ||
var _ref9; | ||
if (_isArray9) { | ||
if (_i9 >= _iterator9.length) break; | ||
_ref9 = _iterator9[_i9++]; | ||
} else { | ||
_i9 = _iterator9.next(); | ||
if (_i9.done) break; | ||
_ref9 = _i9.value; | ||
} | ||
var plugin = _ref9; | ||
if (plugin.onResetField) { | ||
if (plugin.onResetField(name, form)) { | ||
return; | ||
} | ||
} | ||
} | ||
var initialValue = _this4.fields[name].initialValue === undefined ? _this4.getInitialValue(name) : _this4.fields[name].initialValue; | ||
@@ -626,15 +662,15 @@ _this4.dispatch((0, _actions.setFieldValue)(name, initialValue)); | ||
for (var _iterator8 = Object.keys(fields), _isArray8 = Array.isArray(_iterator8), _i8 = 0, _iterator8 = _isArray8 ? _iterator8 : _iterator8[Symbol.iterator]();;) { | ||
var _ref8; | ||
for (var _iterator10 = Object.keys(fields), _isArray10 = Array.isArray(_iterator10), _i10 = 0, _iterator10 = _isArray10 ? _iterator10 : _iterator10[Symbol.iterator]();;) { | ||
var _ref10; | ||
if (_isArray8) { | ||
if (_i8 >= _iterator8.length) break; | ||
_ref8 = _iterator8[_i8++]; | ||
if (_isArray10) { | ||
if (_i10 >= _iterator10.length) break; | ||
_ref10 = _iterator10[_i10++]; | ||
} else { | ||
_i8 = _iterator8.next(); | ||
if (_i8.done) break; | ||
_ref8 = _i8.value; | ||
_i10 = _iterator10.next(); | ||
if (_i10.done) break; | ||
_ref10 = _i10.value; | ||
} | ||
var field = _ref8; | ||
var field = _ref10; | ||
@@ -651,15 +687,15 @@ // Remove unmounted `<Field/>`s. | ||
for (var _iterator9 = _this4.plugins, _isArray9 = Array.isArray(_iterator9), _i9 = 0, _iterator9 = _isArray9 ? _iterator9 : _iterator9[Symbol.iterator]();;) { | ||
var _ref9; | ||
for (var _iterator11 = _this4.plugins, _isArray11 = Array.isArray(_iterator11), _i11 = 0, _iterator11 = _isArray11 ? _iterator11 : _iterator11[Symbol.iterator]();;) { | ||
var _ref11; | ||
if (_isArray9) { | ||
if (_i9 >= _iterator9.length) break; | ||
_ref9 = _iterator9[_i9++]; | ||
if (_isArray11) { | ||
if (_i11 >= _iterator11.length) break; | ||
_ref11 = _iterator11[_i11++]; | ||
} else { | ||
_i9 = _iterator9.next(); | ||
if (_i9.done) break; | ||
_ref9 = _i9.value; | ||
_i11 = _iterator11.next(); | ||
if (_i11.done) break; | ||
_ref11 = _i11.value; | ||
} | ||
var plugin = _ref9; | ||
var plugin = _ref11; | ||
@@ -817,2 +853,3 @@ if (plugin.onAfterSubmit) { | ||
onUnregisterField: _propTypes2.default.func.isRequired, | ||
onRegisterList: _propTypes2.default.func.isRequired, | ||
focus: _propTypes2.default.isRequired, | ||
@@ -819,0 +856,0 @@ dispatch: _propTypes2.default.func.isRequired, |
@@ -56,2 +56,6 @@ 'use strict'; | ||
_this.onReset = function (callback) { | ||
_this.setState(_this.getInitialItemsState(), callback); | ||
}; | ||
_this.getFieldName = function (i, name) { | ||
@@ -106,28 +110,2 @@ if (typeof i !== 'number') { | ||
_this.reset = function () { | ||
var _this$props = _this.props, | ||
name = _this$props.name, | ||
context = _this$props.context; | ||
for (var _iterator = Object.keys(context.fields), _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) { | ||
var _ref; | ||
if (_isArray) { | ||
if (_i >= _iterator.length) break; | ||
_ref = _iterator[_i++]; | ||
} else { | ||
_i = _iterator.next(); | ||
if (_i.done) break; | ||
_ref = _i.value; | ||
} | ||
var field = _ref; | ||
if (field.indexOf(name + ':') === 0) { | ||
context.resetField(field); | ||
} | ||
} | ||
_this.setState(_this.getInitialItemsState(), context.cleanUpRemovedFields); | ||
}; | ||
_this.state = _extends({ | ||
@@ -143,9 +121,20 @@ context: { | ||
_createClass(List, [{ | ||
key: 'getInitialItems', | ||
value: function getInitialItems() { | ||
key: 'componentDidMount', | ||
value: function componentDidMount() { | ||
var _props = this.props, | ||
context = _props.context, | ||
name = _props.name, | ||
count = _props.count; | ||
context = _props.context; | ||
context.onRegisterList(name, { | ||
onReset: this.onReset | ||
}); | ||
} | ||
}, { | ||
key: 'getInitialItems', | ||
value: function getInitialItems() { | ||
var _props2 = this.props, | ||
context = _props2.context, | ||
name = _props2.name, | ||
count = _props2.count; | ||
if (context.initialValues[name]) { | ||
@@ -165,5 +154,2 @@ return createIndexArray(context.initialValues[name].length); | ||
} | ||
// Hasn't been tested. | ||
}, { | ||
@@ -170,0 +156,0 @@ key: 'render', |
@@ -17,5 +17,20 @@ 'use strict'; | ||
_classCallCheck(this, ListPlugin); | ||
this.lists = {}; | ||
} | ||
// Tracks `<List/>`s. | ||
_createClass(ListPlugin, [{ | ||
key: 'initContext', | ||
value: function initContext(context) { | ||
var _this = this; | ||
context.onRegisterList = function (name, _ref) { | ||
var onReset = _ref.onReset; | ||
_this.lists[name] = { onReset: onReset }; | ||
}; | ||
} | ||
}, { | ||
key: 'getValues', | ||
@@ -32,2 +47,30 @@ value: function getValues(values) { | ||
} | ||
}, { | ||
key: 'onResetField', | ||
value: function onResetField(name, form) { | ||
if (this.lists[name]) { | ||
var fields = form.state.fields; | ||
for (var _iterator = Object.keys(fields), _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) { | ||
var _ref2; | ||
if (_isArray) { | ||
if (_i >= _iterator.length) break; | ||
_ref2 = _iterator[_i++]; | ||
} else { | ||
_i = _iterator.next(); | ||
if (_i.done) break; | ||
_ref2 = _i.value; | ||
} | ||
var field = _ref2; | ||
if (field.indexOf(name + ':') === 0) { | ||
form.resetField(field); | ||
} | ||
} | ||
this.lists[name].onReset(form.cleanUpRemovedFields); | ||
return true; | ||
} | ||
} | ||
}]); | ||
@@ -34,0 +77,0 @@ |
{ | ||
"name": "easy-react-form", | ||
"version": "1.0.19", | ||
"version": "1.0.20", | ||
"description": "Simple, fast and easy-to-use React Form.", | ||
@@ -5,0 +5,0 @@ "main": "index.commonjs.js", |
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
280650
3163