function Field(props, context) {
_classCallCheck(this, Field);
var _this = _possibleConstructorReturn(this, (Field.__proto__ || Object.getPrototypeOf(Field)).call(this, props, context));
if (!context._reduxForm) {
throw new Error('Field must be inside a component decorated with reduxForm()');
}
_this.normalize = _this.normalize.bind(_this);
return _this;
}n/a
function FieldArray(props, context) {
_classCallCheck(this, FieldArray);
var _this = _possibleConstructorReturn(this, (FieldArray.__proto__ || Object.getPrototypeOf(FieldArray)).call(this, props, context
));
if (!context._reduxForm) {
throw new Error('FieldArray must be inside a component decorated with reduxForm()');
}
return _this;
}n/a
function Fields(props, context) {
_classCallCheck(this, Fields);
var _this = _possibleConstructorReturn(this, (Fields.__proto__ || Object.getPrototypeOf(Fields)).call(this, props, context));
if (!context._reduxForm) {
throw new Error('Fields must be inside a component decorated with reduxForm()');
}
return _this;
}n/a
function Form(props, context) {
_classCallCheck(this, Form);
var _this = _possibleConstructorReturn(this, (Form.__proto__ || Object.getPrototypeOf(Form)).call(this, props, context));
if (!context._reduxForm) {
throw new Error('Form must be inside a component decorated with reduxForm()');
}
return _this;
}n/a
function FormSection(props, context) {
_classCallCheck(this, FormSection);
var _this = _possibleConstructorReturn(this, (FormSection.__proto__ || Object.getPrototypeOf(FormSection)).call(this, props, context
));
if (!context._reduxForm) {
throw new Error('FormSection must be inside a component decorated with reduxForm()');
}
return _this;
}n/a
function SubmissionError(errors) {
_classCallCheck(this, SubmissionError);
var _this = _possibleConstructorReturn(this, (SubmissionError.__proto__ || Object.getPrototypeOf(SubmissionError)).call(this, '
Submit Validation Failed'));
_this.errors = errors;
return _this;
}n/a
function arrayInsert(form, field, index, value) {
return { type: _actionTypes.ARRAY_INSERT, meta: { form: form, field: field, index: index }, payload: value };
}n/a
function arrayMove(form, field, from, to) {
return { type: _actionTypes.ARRAY_MOVE, meta: { form: form, field: field, from: from, to: to } };
}n/a
function arrayPop(form, field) {
return { type: _actionTypes.ARRAY_POP, meta: { form: form, field: field } };
}n/a
function arrayPush(form, field, value) {
return { type: _actionTypes.ARRAY_PUSH, meta: { form: form, field: field }, payload: value };
}n/a
function arrayRemove(form, field, index) {
return { type: _actionTypes.ARRAY_REMOVE, meta: { form: form, field: field, index: index } };
}n/a
function arrayRemoveAll(form, field) {
return { type: _actionTypes.ARRAY_REMOVE_ALL, meta: { form: form, field: field } };
}n/a
function arrayShift(form, field) {
return { type: _actionTypes.ARRAY_SHIFT, meta: { form: form, field: field } };
}n/a
function arraySplice(form, field, index, removeNum, value) {
var action = {
type: _actionTypes.ARRAY_SPLICE,
meta: { form: form, field: field, index: index, removeNum: removeNum }
};
if (value !== undefined) {
action.payload = value;
}
return action;
}n/a
function arraySwap(form, field, indexA, indexB) {
if (indexA === indexB) {
throw new Error('Swap indices cannot be equal');
}
if (indexA < 0 || indexB < 0) {
throw new Error('Swap indices cannot be negative');
}
return { type: _actionTypes.ARRAY_SWAP, meta: { form: form, field: field, indexA: indexA, indexB: indexB } };
}n/a
function arrayUnshift(form, field, value) {
return { type: _actionTypes.ARRAY_UNSHIFT, meta: { form: form, field: field }, payload: value };
}n/a
function autofill(form, field, value) {
return { type: _actionTypes.AUTOFILL, meta: { form: form, field: field }, payload: value };
}n/a
function blur(form, field, value, touch) {
return { type: _actionTypes.BLUR, meta: { form: form, field: field, touch: touch }, payload: value };
}...
return event.preventDefault();
}
}), newValue, previousValue);
}
if (!defaultPrevented) {
// dispatch blur action
dispatch(_reduxForm.blur(name, newValue));
// call post-blur callback
if (_reduxForm.asyncValidate) {
_reduxForm.asyncValidate(name, newValue);
}
}
}
...function change(form, field, value, touch, persistentSubmitErrors) {
return { type: _actionTypes.CHANGE, meta: { form: form, field: field, touch: touch, persistentSubmitErrors: persistentSubmitErrors
}, payload: value };
}...
defaultPrevented = true;
return event.preventDefault();
}
}), newValue, previousValue);
}
if (!defaultPrevented) {
// dispatch change action
dispatch(_reduxForm.change(name, newValue));
}
}
}, {
key: 'handleFocus',
value: function handleFocus(event) {
var _props2 = this.props,
name = _props2.name,
...function clearSubmitErrors(form) {
return { type: _actionTypes.CLEAR_SUBMIT_ERRORS, meta: { form: form } };
}n/a
function destroy() {
for (var _len = arguments.length, form = Array(_len), _key = 0; _key < _len; _key++) {
form[_key] = arguments[_key];
}
return { type: _actionTypes.DESTROY, meta: { form: form } };
}n/a
function focus(form, field) {
return { type: _actionTypes.FOCUS, meta: { form: form, field: field } };
}...
defaultPrevented = true;
return event.preventDefault();
}
}));
}
if (!defaultPrevented) {
dispatch(_reduxForm.focus(name));
}
}
}, {
key: 'handleBlur',
value: function handleBlur(event) {
var _props3 = this.props,
name = _props3.name,
...formValueSelector = function (form) {
var getFormState = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : function (state) {
return getIn(state, 'form');
};
(0, _invariant2.default)(form, 'Form value must be specified');
return function (state) {
for (var _len = arguments.length, fields = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
fields[_key - 1] = arguments[_key];
}
(0, _invariant2.default)(fields.length, 'No fields specified');
return fields.length === 1 ?
// only selecting one field, so return its value
getIn(getFormState(state), form + '.values.' + fields[0]) :
// selecting many fields, so return an object of field values
fields.reduce(function (accumulator, field) {
var value = getIn(getFormState(state), form + '.values.' + field);
return value === undefined ? accumulator : _plain2.default.setIn(accumulator, field, value);
}, {});
};
}n/a
getFormAsyncErrors = function (form) {
var getFormState = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : function (state) {
return getIn(state, 'form');
};
return function (state) {
return getIn(getFormState(state), form + '.asyncErrors');
};
}n/a
getFormInitialValues = function (form) {
var getFormState = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : function (state) {
return getIn(state, 'form');
};
return function (state) {
return getIn(getFormState(state), form + '.initial');
};
}n/a
getFormNames = function () {
var getFormState = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : function (state) {
return getIn(state, 'form');
};
return function (state) {
return keys(getFormState(state));
};
}n/a
getFormSubmitErrors = function (form) {
var getFormState = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : function (state) {
return getIn(state, 'form');
};
return function (state) {
return getIn(getFormState(state), form + '.submitErrors');
};
}n/a
getFormSyncErrors = function (form) {
var getFormState = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : function (state) {
return getIn(state, 'form');
};
return function (state) {
return getIn(getFormState(state), form + '.syncErrors');
};
}n/a
getFormSyncWarnings = function (form) {
var getFormState = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : function (state) {
return getIn(state, 'form');
};
return function (state) {
return getIn(getFormState(state), form + '.syncWarnings');
};
}n/a
getFormValues = function (form) {
var getFormState = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : function (state) {
return getIn(state, 'form');
};
return function (state) {
return getIn(getFormState(state), form + '.values');
};
}n/a
hasSubmitFailed = function (form) {
var getFormState = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : function (state) {
return getIn(state, 'form');
};
return function (state) {
var formState = getFormState(state);
return getIn(formState, form + '.submitFailed') || false;
};
}n/a
hasSubmitSucceeded = function (form) {
var getFormState = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : function (state) {
return getIn(state, 'form');
};
return function (state) {
var formState = getFormState(state);
return getIn(formState, form + '.submitSucceeded') || false;
};
}n/a
function initialize(form, values, keepDirty) {
var otherMeta = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
if (keepDirty instanceof Object) {
otherMeta = keepDirty;
keepDirty = false;
}
return { type: _actionTypes.INITIALIZE, meta: _extends({ form: form, keepDirty: keepDirty }, otherMeta), payload: values };
}...
key: 'initIfNeeded',
value: function initIfNeeded(nextProps) {
var enableReinitialize = this.props.enableReinitialize;
if (nextProps) {
if ((enableReinitialize || !nextProps.initialized) && !deepEqual(this.props.initialValues, nextProps.initialValues
)) {
var keepDirty = nextProps.initialized && this.props.keepDirtyOnReinitialize;
this.props.initialize(nextProps.initialValues, keepDirty);
}
} else if (this.props.initialValues && (!this.props.initialized || enableReinitialize)) {
this.props.initialize(this.props.initialValues, this.props.keepDirtyOnReinitialize);
}
}
}, {
key: 'updateSyncErrorsIfNeeded',
...isDirty = function (form, getFormState) {
var isPristine = (0, _isPristine2.default)(structure)(form, getFormState);
return function (state) {
return !isPristine(state);
};
}...
return this.props.names.map(function (name) {
return (0, _prefixName2.default)(context, name);
});
}
}, {
key: 'dirty',
get: function get() {
return this.refs.connected.getWrappedInstance().isDirty();
}
}, {
key: 'pristine',
get: function get() {
return !this.dirty;
}
}, {
...isInvalid = function (form, getFormState) {
var isValid = (0, _isValid2.default)(structure)(form, getFormState);
return function (state) {
return !isValid(state);
};
}n/a
isPristine = function (form) {
var getFormState = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : function (state) {
return getIn(state, 'form');
};
return function (state) {
var formState = getFormState(state);
var initial = getIn(formState, form + '.initial') || empty;
var values = getIn(formState, form + '.values') || initial;
return deepEqual(initial, values);
};
}...
key: 'dirty',
get: function get() {
return !this.pristine;
}
}, {
key: 'pristine',
get: function get() {
return this.refs.connected.getWrappedInstance().isPristine();
}
}, {
key: 'value',
get: function get() {
return this.refs.connected && this.refs.connected.getWrappedInstance().getValue();
}
}]);
...isSubmitting = function (form) {
var getFormState = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : function (state) {
return getIn(state, 'form');
};
return function (state) {
var formState = getFormState(state);
return getIn(formState, form + '.submitting') || false;
};
}n/a
isValid = function (form) {
var getFormState = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : function (state) {
return getIn(state, 'form');
};
var ignoreSubmitErrors = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
return function (state) {
var formState = getFormState(state);
var syncError = getIn(formState, form + '.syncError');
if (syncError) {
return false;
}
if (!ignoreSubmitErrors) {
var error = getIn(formState, form + '.error');
if (error) {
return false;
}
}
var syncErrors = getIn(formState, form + '.syncErrors');
var asyncErrors = getIn(formState, form + '.asyncErrors');
var submitErrors = ignoreSubmitErrors ? undefined : getIn(formState, form + '.submitErrors');
if (!syncErrors && !asyncErrors && !submitErrors) {
return true;
}
var registeredFields = getIn(formState, form + '.registeredFields');
if (!registeredFields) {
return true;
}
return !keys(registeredFields).filter(function (name) {
return getIn(registeredFields, '[\'' + name + '\'].count') > 0;
}).some(function (name) {
return hasError(getIn(registeredFields, '[\'' + name + '\']'), syncErrors, asyncErrors, submitErrors);
});
};
}...
// convert initialValues if need to
initialValues: fromJS(initialValues)
}));
}
}, {
key: 'valid',
get: function get() {
return this.refs.wrapped.getWrappedInstance().isValid();
}
}, {
key: 'invalid',
get: function get() {
return !this.valid;
}
}, {
...propTypes.array = function () { [native code] }n/a
propTypes.error = function () { [native code] }n/a
propTypes.initialValues = function () { [native code] }n/a
propTypes.triggerSubmit = function () { [native code] }n/a
reducer = function () {
var state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : empty;
var action = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
var form = action && action.meta && action.meta.form;
if (!form || !isReduxFormAction(action)) {
return state;
}
if (action.type === _actionTypes.DESTROY) {
return action.meta.form.reduce(function (result, form) {
return deleteInWithCleanUp(result, form);
}, state);
}
var formState = getIn(state, form);
var result = reducer(formState, action);
return result === formState ? state : setIn(state, form, result);
}n/a
reduxForm = function (initialConfig) {
var config = _extends({
touchOnBlur: true,
touchOnChange: false,
persistentSubmitErrors: false,
destroyOnUnmount: true,
shouldAsyncValidate: _defaultShouldAsyncValidate2.default,
shouldValidate: _defaultShouldValidate2.default,
enableReinitialize: false,
keepDirtyOnReinitialize: false,
getFormState: function getFormState(state) {
return getIn(state, 'form');
},
pure: true,
forceUnregisterOnUnmount: false
}, initialConfig);
return function (WrappedComponent) {
var Form = function (_Component) {
_inherits(Form, _Component);
function Form(props) {
_classCallCheck(this, Form);
var _this = _possibleConstructorReturn(this, (Form.__proto__ || Object.getPrototypeOf(Form)).call(this, props));
_this.submit = _this.submit.bind(_this);
_this.reset = _this.reset.bind(_this);
_this.asyncValidate = _this.asyncValidate.bind(_this);
_this.getValues = _this.getValues.bind(_this);
_this.register = _this.register.bind(_this);
_this.unregister = _this.unregister.bind(_this);
_this.submitCompleted = _this.submitCompleted.bind(_this);
_this.submitFailed = _this.submitFailed.bind(_this);
_this.fieldValidators = {};
_this.lastFieldValidatorKeys = [];
_this.fieldWarners = {};
_this.lastFieldWarnerKeys = [];
return _this;
}
_createClass(Form, [{
key: 'getChildContext',
value: function getChildContext() {
var _this2 = this;
return {
_reduxForm: _extends({}, this.props, {
getFormState: function getFormState(state) {
return getIn(_this2.props.getFormState(state), _this2.props.form);
},
asyncValidate: this.asyncValidate,
getValues: this.getValues,
sectionPrefix: undefined,
register: this.register,
unregister: this.unregister,
registerInnerOnSubmit: function registerInnerOnSubmit(innerOnSubmit) {
return _this2.innerOnSubmit = innerOnSubmit;
}
})
};
}
}, {
key: 'initIfNeeded',
value: function initIfNeeded(nextProps) {
var enableReinitialize = this.props.enableReinitialize;
if (nextProps) {
if ((enableReinitialize || !nextProps.initialized) && !deepEqual(this.props.initialValues, nextProps.initialValues)) {
var keepDirty = nextProps.initialized && this.props.keepDirtyOnReinitialize;
this.props.initialize(nextProps.initialValues, keepDirty);
}
} else if (this.props.initialValues && (!this.props.initialized || enableReinitialize)) {
this.props.initialize(this.props.initialValues, this.props.keepDirtyOnReinitialize);
}
}
}, {
key: 'updateSyncErrorsIfNeeded',
value: function updateSyncErrorsIfNeeded(nextSyncErrors, nextError) {
var _props = this.props,
error = _props.error,
updateSyncErrors = _props.updateSyncErrors;
var noErrors = (!this.lastSyncErrors || !Object.keys(this.lastSyncErrors).length) && !error;
var nextNoErrors = (!nextSyncErrors || !Object.keys(nextSyncErrors).length) && !nextError;
if (!(noErrors && nextNoErrors) && (!_plain2.default.deepEqual(this.lastSyncErrors, nextSyncErrors) || !_plain2.default
.deepEqual(error, nextError))) {
this.lastSyncErrors = nextSyncErrors;
updateSyncErrors(nextSyncErrors, nextError);
}
}
}, {
key: 'clearSubmitPromiseIfNeeded',
value: function clearSubmitPromiseIfNeeded(nextProps) {
var submitting = this.props.submitting;
if (this.submitPromise && submitting && !nextProps.submitting) {
delete this.submitPromise;
}
}
}, {
key: 'submitIfNeeded',
value: function submitIfNeeded(nextProps) { ...n/a
function registerField(form, name, type) {
return { type: _actionTypes.REGISTER_FIELD, meta: { form: form }, payload: { name: name, type: type } };
}...
key: 'isPristine',
value: function isPristine() {
return this.props.pristine;
}
}, {
key: 'register',
value: function register(name, type, getValidator, getWarner) {
this.props.registerField(name, type);
if (getValidator) {
this.fieldValidators[name] = getValidator;
}
if (getWarner) {
this.fieldWarners[name] = getWarner;
}
}
...function reset(form) {
return { type: _actionTypes.RESET, meta: { form: form } };
}...
return !_this7.submitPromise && _this7.listenToSubmit((0, _handleSubmit2.default)(checkSubmit(submitOrEvent),
_extends({}, _this7.props, (0, _redux.bindActionCreators)({ blur: blur, change: change }, dispatch)), _this7.props.validExceptSubmit
, _this7.asyncValidate, _this7.getFieldList({ excludeFieldArray: true })));
});
}
}
}, {
key: 'reset',
value: function reset() {
this.props.reset();
}
}, {
key: 'render',
value: function render() {
// remove some redux-form config-only props
/* eslint-disable no-unused-vars */
var _props9 = this.props,
...function setSubmitFailed(form) {
for (var _len2 = arguments.length, fields = Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
fields[_key2 - 1] = arguments[_key2];
}
return { type: _actionTypes.SET_SUBMIT_FAILED, meta: { form: form, fields: fields }, error: true };
}n/a
function setSubmitSucceeded(form) {
for (var _len3 = arguments.length, fields = Array(_len3 > 1 ? _len3 - 1 : 0), _key3 = 1; _key3 < _len3; _key3++) {
fields[_key3 - 1] = arguments[_key3];
}
return { type: _actionTypes.SET_SUBMIT_SUCCEEDED, meta: { form: form, fields: fields }, error: false };
}n/a
function startAsyncValidation(form, field) {
return { type: _actionTypes.START_ASYNC_VALIDATION, meta: { form: form, field: field } };
}n/a
function startSubmit(form) {
return { type: _actionTypes.START_SUBMIT, meta: { form: form } };
}n/a
function stopAsyncValidation(form, errors) {
var action = {
type: _actionTypes.STOP_ASYNC_VALIDATION,
meta: { form: form },
payload: errors
};
if (errors && Object.keys(errors).length) {
action.error = true;
}
return action;
}n/a
function stopSubmit(form, errors) {
var action = {
type: _actionTypes.STOP_SUBMIT,
meta: { form: form },
payload: errors
};
if (errors && Object.keys(errors).length) {
action.error = true;
}
return action;
}n/a
function submit(form) {
return { type: _actionTypes.SUBMIT, meta: { form: form } };
}...
value: function submitIfNeeded(nextProps) {
var _props2 = this.props,
clearSubmit = _props2.clearSubmit,
triggerSubmit = _props2.triggerSubmit;
if (!triggerSubmit && nextProps.triggerSubmit) {
clearSubmit();
this.submit();
}
}
}, {
key: 'validateIfNeeded',
value: function validateIfNeeded(nextProps) {
var _props3 = this.props,
shouldValidate = _props3.shouldValidate,
...function touch(form) {
for (var _len4 = arguments.length, fields = Array(_len4 > 1 ? _len4 - 1 : 0), _key4 = 1; _key4 < _len4; _key4++) {
fields[_key4 - 1] = arguments[_key4];
}
return { type: _actionTypes.TOUCH, meta: { form: form, fields: fields } };
}n/a
function unregisterField(form, name) {
var destroyOnUnmount = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
return { type: _actionTypes.UNREGISTER_FIELD, meta: { form: form }, payload: { name: name, destroyOnUnmount: destroyOnUnmount } };
}...
}
}
}, {
key: 'unregister',
value: function unregister(name) {
if (!this.destroyed) {
if (this.props.destroyOnUnmount || this.props.forceUnregisterOnUnmount) {
this.props.unregisterField(name);
delete this.fieldValidators[name];
delete this.fieldWarners[name];
} else {
this.props.unregisterField(name, false);
}
}
}
...function untouch(form) {
for (var _len5 = arguments.length, fields = Array(_len5 > 1 ? _len5 - 1 : 0), _key5 = 1; _key5 < _len5; _key5++) {
fields[_key5 - 1] = arguments[_key5];
}
return { type: _actionTypes.UNTOUCH, meta: { form: form, fields: fields } };
}n/a
values = function (config) {
var _prop$getFormState$co = _extends({
prop: 'values',
getFormState: function getFormState(state) {
return getIn(state, 'form');
}
}, config),
form = _prop$getFormState$co.form,
prop = _prop$getFormState$co.prop,
getFormState = _prop$getFormState$co.getFormState;
return (0, _reactRedux.connect)(function (state) {
return _defineProperty({}, prop, getIn(getFormState(state), form + '.values'));
}, function () {
return {};
} // ignore dispatch
);
}n/a
function createConnectedField(_ref) {
var deepEqual = _ref.deepEqual,
getIn = _ref.getIn,
toJS = _ref.toJS;
var getSyncError = function getSyncError(syncErrors, name) {
var error = _plain2.default.getIn(syncErrors, name);
// Because the error for this field might not be at a level in the error structure where
// it can be set directly, it might need to be unwrapped from the _error property
return error && error._error ? error._error : error;
};
var getSyncWarning = function getSyncWarning(syncWarnings, name) {
var warning = getIn(syncWarnings, name);
// Because the warning for this field might not be at a level in the warning structure where
// it can be set directly, it might need to be unwrapped from the _warning property
return warning && warning._warning ? warning._warning : warning;
};
var ConnectedField = function (_Component) {
_inherits(ConnectedField, _Component);
function ConnectedField(props) {
_classCallCheck(this, ConnectedField);
var _this = _possibleConstructorReturn(this, (ConnectedField.__proto__ || Object.getPrototypeOf(ConnectedField)).call(this
, props));
_this.handleChange = _this.handleChange.bind(_this);
_this.handleFocus = _this.handleFocus.bind(_this);
_this.handleBlur = _this.handleBlur.bind(_this);
_this.handleDragStart = _this.handleDragStart.bind(_this);
_this.handleDrop = _this.handleDrop.bind(_this);
return _this;
}
_createClass(ConnectedField, [{
key: 'shouldComponentUpdate',
value: function shouldComponentUpdate(nextProps) {
var _this2 = this;
var nextPropsKeys = Object.keys(nextProps);
var thisPropsKeys = Object.keys(this.props);
return nextPropsKeys.length !== thisPropsKeys.length || nextPropsKeys.some(function (prop) {
return !~propsToNotUpdateFor.indexOf(prop) && !deepEqual(_this2.props[prop], nextProps[prop]);
});
}
}, {
key: 'isPristine',
value: function isPristine() {
return this.props.pristine;
}
}, {
key: 'getValue',
value: function getValue() {
return this.props.value;
}
}, {
key: 'getRenderedComponent',
value: function getRenderedComponent() {
return this.refs.renderedComponent;
}
}, {
key: 'handleChange',
value: function handleChange(event) {
var _props = this.props,
name = _props.name,
dispatch = _props.dispatch,
parse = _props.parse,
normalize = _props.normalize,
onChange = _props.onChange,
_reduxForm = _props._reduxForm,
previousValue = _props.value;
var newValue = (0, _onChangeValue2.default)(event, { name: name, parse: parse, normalize: normalize });
var defaultPrevented = false;
if (onChange) {
onChange(_extends({}, event, {
preventDefault: function preventDefault() {
defaultPrevented = true;
return event.preventDefault();
}
}), newValue, previousValue);
}
if (!defaultPrevented) {
// dispatch change action
dispatch(_reduxForm.change(name, newValue));
}
}
}, {
key: 'handleFocus',
value: function handleFocus(event) {
var _props2 = this.props,
name = _props2.name,
dispatch = _props2.dispatch,
onFocus = _props2.onFocus,
_reduxForm = _props2._reduxForm;
var defaultPrevented = false;
if (onFocus) {
onFocus(_extends({}, event, {
preventDefault: function preventDefault() {
defaultPrevented = true;
return event.preventDefault();
}
}));
}
if (!defaultPrevented) {
dispatch(_reduxForm.focus(name));
}
}
}, {
key: 'handleBlur',
value: function handleBlur(event) {
var _props3 = this.props,
name = _props3.name, ...n/a
function createConnectedFieldArray(_ref) {
var deepEqual = _ref.deepEqual,
getIn = _ref.getIn,
size = _ref.size;
var getSyncError = function getSyncError(syncErrors, name) {
// For an array, the error can _ONLY_ be under _error.
// This is why this getSyncError is not the same as the
// one in Field.
return _plain2.default.getIn(syncErrors, name + '._error');
};
var getSyncWarning = function getSyncWarning(syncWarnings, name) {
// For an array, the warning can _ONLY_ be under _warning.
// This is why this getSyncError is not the same as the
// one in Field.
return getIn(syncWarnings, name + '._warning');
};
var ConnectedFieldArray = function (_Component) {
_inherits(ConnectedFieldArray, _Component);
function ConnectedFieldArray() {
_classCallCheck(this, ConnectedFieldArray);
var _this = _possibleConstructorReturn(this, (ConnectedFieldArray.__proto__ || Object.getPrototypeOf(ConnectedFieldArray)).
call(this));
_this.getValue = _this.getValue.bind(_this);
return _this;
}
_createClass(ConnectedFieldArray, [{
key: 'shouldComponentUpdate',
value: function shouldComponentUpdate(nextProps) {
var _this2 = this;
// Update if the elements of the value array was updated.
var thisValue = this.props.value;
var nextValue = nextProps.value;
if (thisValue && nextValue) {
if (thisValue.length !== nextValue.length || thisValue.every(function (val) {
return nextValue.some(function (next) {
return deepEqual(val, next);
});
})) {
return true;
}
}
var nextPropsKeys = Object.keys(nextProps);
var thisPropsKeys = Object.keys(this.props);
return nextPropsKeys.length !== thisPropsKeys.length || nextPropsKeys.some(function (prop) {
// useful to debug rerenders
// if (!plain.deepEqual(this.props[ prop ], nextProps[ prop ])) {
// console.info(prop, 'changed', this.props[ prop ], '==>', nextProps[ prop ])
// }
return !~propsToNotUpdateFor.indexOf(prop) && !deepEqual(_this2.props[prop], nextProps[prop]);
});
}
}, {
key: 'getRenderedComponent',
value: function getRenderedComponent() {
return this.refs.renderedComponent;
}
}, {
key: 'getValue',
value: function getValue(index) {
return this.props.value && getIn(this.props.value, index);
}
}, {
key: 'render',
value: function render() {
var _props = this.props,
component = _props.component,
withRef = _props.withRef,
name = _props.name,
_reduxForm = _props._reduxForm,
validate = _props.validate,
warn = _props.warn,
rest = _objectWithoutProperties(_props, ['component', 'withRef', 'name', '_reduxForm', 'validate', 'warn']);
var props = (0, _createFieldArrayProps2.default)(getIn, name, _reduxForm.form, _reduxForm.sectionPrefix, this.getValue,
rest);
if (withRef) {
props.ref = 'renderedComponent';
}
return (0, _react.createElement)(component, props);
}
}, {
key: 'dirty',
get: function get() {
return this.props.dirty;
}
}, {
key: 'pristine',
get: function get() {
return this.props.pristine;
}
}, {
key: 'value',
get: function get() {
return this.props.value;
}
}]);
return ConnectedFieldArray;
}(_react.Component);
ConnectedFieldArray.propTypes = {
component: _propTypes2.default.oneOfType([_propTypes2.default.func, _propTypes2.default.string]).isRequired,
props: _propTypes2.default.object
};
ConnectedFieldArray.contextTypes = {
_reduxForm: _propTypes2.default.object
};
var connector = (0, _reactRedux.connect)(function (state, ownProps) {
var name = ownProps.name,
_ownProps$_reduxForm = ownProps._reduxForm,
initialValues = _ownPr ...n/a
function createConnectedFields(_ref) {
var deepEqual = _ref.deepEqual,
getIn = _ref.getIn,
toJS = _ref.toJS,
size = _ref.size;
var getSyncError = function getSyncError(syncErrors, name) {
// Because the error for this field might not be at a level in the error structure where
// it can be set directly, it might need to be unwrapped from the _error property
return _plain2.default.getIn(syncErrors, name + '._error') || _plain2.default.getIn(syncErrors, name);
};
var getSyncWarning = function getSyncWarning(syncWarnings, name) {
var warning = getIn(syncWarnings, name);
// Because the warning for this field might not be at a level in the warning structure where
// it can be set directly, it might need to be unwrapped from the _warning property
return warning && warning._warning ? warning._warning : warning;
};
var ConnectedFields = function (_Component) {
_inherits(ConnectedFields, _Component);
function ConnectedFields(props) {
_classCallCheck(this, ConnectedFields);
var _this = _possibleConstructorReturn(this, (ConnectedFields.__proto__ || Object.getPrototypeOf(ConnectedFields)).call(this
, props));
_this.handleChange = _this.handleChange.bind(_this);
_this.handleFocus = _this.handleFocus.bind(_this);
_this.handleBlur = _this.handleBlur.bind(_this);
_this.onChangeFns = props.names.reduce(function (acc, name) {
acc[name] = function (event) {
return _this.handleChange(name, event);
};
return acc;
}, {});
_this.onFocusFns = props.names.reduce(function (acc, name) {
acc[name] = function () {
return _this.handleFocus(name);
};
return acc;
}, {});
_this.onBlurFns = props.names.reduce(function (acc, name) {
acc[name] = function (event) {
return _this.handleBlur(name, event);
};
return acc;
}, {});
return _this;
}
_createClass(ConnectedFields, [{
key: 'componentWillReceiveProps',
value: function componentWillReceiveProps(nextProps) {
var _this2 = this;
if (this.props.names !== nextProps.names && (size(this.props.names) !== size(nextProps.names) || nextProps.names.some(function
(nextName) {
return !_this2.props._fields[nextName];
}))) {
// names is changed. The cached event handlers need to be updated
this.onChangeFns = nextProps.names.reduce(function (acc, name) {
acc[name] = function (event) {
return _this2.handleChange(name, event);
};
return acc;
}, {});
this.onFocusFns = nextProps.names.reduce(function (acc, name) {
acc[name] = function () {
return _this2.handleFocus(name);
};
return acc;
}, {});
this.onBlurFns = nextProps.names.reduce(function (acc, name) {
acc[name] = function (event) {
return _this2.handleBlur(name, event);
};
return acc;
}, {});
}
}
}, {
key: 'shouldComponentUpdate',
value: function shouldComponentUpdate(nextProps) {
var _this3 = this;
var nextPropsKeys = Object.keys(nextProps);
var thisPropsKeys = Object.keys(this.props);
return nextPropsKeys.length !== thisPropsKeys.length || nextPropsKeys.some(function (prop) {
return !~propsToNotUpdateFor.indexOf(prop) && !deepEqual(_this3.props[prop], nextProps[prop]);
});
}
}, {
key: 'isDirty',
value: function isDirty() {
var _fields = this.props._fields;
return Object.keys(_fields).some(function (name) {
return _fields[name].dirty;
});
}
}, {
key: 'getValues',
value: function getValues() {
var _fields = this.props._fields;
return Object.keys(_fields).reduce(function (accumulator, name) {
return _plain2.default.setIn(accumulator, name, _fields[name].value); ...n/a
function createField(_ref) {
var deepEqual = _ref.deepEqual,
getIn = _ref.getIn,
setIn = _ref.setIn,
toJS = _ref.toJS;
var ConnectedField = (0, _ConnectedField2.default)({
deepEqual: deepEqual,
getIn: getIn,
toJS: toJS
});
var Field = function (_Component) {
_inherits(Field, _Component);
function Field(props, context) {
_classCallCheck(this, Field);
var _this = _possibleConstructorReturn(this, (Field.__proto__ || Object.getPrototypeOf(Field)).call(this, props, context));
if (!context._reduxForm) {
throw new Error('Field must be inside a component decorated with reduxForm()');
}
_this.normalize = _this.normalize.bind(_this);
return _this;
}
_createClass(Field, [{
key: 'shouldComponentUpdate',
value: function shouldComponentUpdate(nextProps, nextState) {
return (0, _shallowCompare2.default)(this, nextProps, nextState);
}
}, {
key: 'componentWillMount',
value: function componentWillMount() {
var _this2 = this;
this.context._reduxForm.register(this.name, 'Field', function () {
return _this2.props.validate;
}, function () {
return _this2.props.warn;
});
}
}, {
key: 'componentWillReceiveProps',
value: function componentWillReceiveProps(nextProps) {
if (this.props.name !== nextProps.name) {
// unregister old name
this.context._reduxForm.unregister(this.name);
// register new name
this.context._reduxForm.register((0, _prefixName2.default)(this.context, nextProps.name), 'Field');
}
}
}, {
key: 'componentWillUnmount',
value: function componentWillUnmount() {
this.context._reduxForm.unregister(this.name);
}
}, {
key: 'getRenderedComponent',
value: function getRenderedComponent() {
(0, _invariant2.default)(this.props.withRef, 'If you want to access getRenderedComponent(), ' + 'you must specify a withRef
prop to Field');
return this.refs.connected.getWrappedInstance().getRenderedComponent();
}
}, {
key: 'normalize',
value: function normalize(name, value) {
var normalize = this.props.normalize;
if (!normalize) {
return value;
}
var previousValues = this.context._reduxForm.getValues();
var previousValue = this.value;
var nextValues = setIn(previousValues, name, value);
return normalize(value, previousValue, nextValues, previousValues);
}
}, {
key: 'render',
value: function render() {
return (0, _react.createElement)(ConnectedField, _extends({}, this.props, {
name: this.name,
normalize: this.normalize,
_reduxForm: this.context._reduxForm,
ref: 'connected'
}));
}
}, {
key: 'name',
get: function get() {
return (0, _prefixName2.default)(this.context, this.props.name);
}
}, {
key: 'dirty',
get: function get() {
return !this.pristine;
}
}, {
key: 'pristine',
get: function get() {
return this.refs.connected.getWrappedInstance().isPristine();
}
}, {
key: 'value',
get: function get() {
return this.refs.connected && this.refs.connected.getWrappedInstance().getValue();
}
}]);
return Field;
}(_react.Component);
Field.propTypes = {
name: _propTypes2.default.string.isRequired,
component: _propTypes2.default.oneOfType([_propTypes2.default.func, _propTypes2.default.string]).isRequired,
format: _propTypes2.default.func,
normalize: _propTypes2.default.func,
onBlur: _propTypes2.default.func,
onChange: _propTypes2.default.func,
onFocus: _propTypes2.default.func,
onDragStart: _propTypes2.default.func,
onDrop: _propTypes2.default.func,
parse: _propTypes2.default.func,
props: _propTypes2.default.object,
validate: _propTypes2.default.oneOfType([_propTypes2.default.func, ...n/a
function createFieldArray(_ref2) {
var deepEqual = _ref2.deepEqual,
getIn = _ref2.getIn,
size = _ref2.size;
var ConnectedFieldArray = (0, _ConnectedFieldArray2.default)({ deepEqual: deepEqual, getIn: getIn, size: size });
var FieldArray = function (_Component) {
_inherits(FieldArray, _Component);
function FieldArray(props, context) {
_classCallCheck(this, FieldArray);
var _this = _possibleConstructorReturn(this, (FieldArray.__proto__ || Object.getPrototypeOf(FieldArray)).call(this, props,
context));
if (!context._reduxForm) {
throw new Error('FieldArray must be inside a component decorated with reduxForm()');
}
return _this;
}
_createClass(FieldArray, [{
key: 'componentWillMount',
value: function componentWillMount() {
var _this2 = this;
this.context._reduxForm.register(this.name, 'FieldArray', function () {
return wrapError(_this2.props.validate, '_error');
}, function () {
return wrapError(_this2.props.warn, '_warning');
});
}
}, {
key: 'componentWillReceiveProps',
value: function componentWillReceiveProps(nextProps) {
if (this.props.name !== nextProps.name) {
// unregister old name
this.context._reduxForm.unregister(this.name);
// register new name
this.context._reduxForm.register((0, _prefixName2.default)(this.context, nextProps.name), 'FieldArray');
}
}
}, {
key: 'componentWillUnmount',
value: function componentWillUnmount() {
this.context._reduxForm.unregister(this.name);
}
}, {
key: 'getRenderedComponent',
value: function getRenderedComponent() {
(0, _invariant2.default)(this.props.withRef, 'If you want to access getRenderedComponent(), ' + 'you must specify a withRef
prop to FieldArray');
return this.refs.connected.getWrappedInstance().getRenderedComponent();
}
}, {
key: 'render',
value: function render() {
return (0, _react.createElement)(ConnectedFieldArray, _extends({}, this.props, {
name: this.name,
syncError: this.syncError,
syncWarning: this.syncWarning,
_reduxForm: this.context._reduxForm,
ref: 'connected'
}));
}
}, {
key: 'name',
get: function get() {
return (0, _prefixName2.default)(this.context, this.props.name);
}
}, {
key: 'dirty',
get: function get() {
return this.refs.connected.getWrappedInstance().dirty;
}
}, {
key: 'pristine',
get: function get() {
return this.refs.connected.getWrappedInstance().pristine;
}
}, {
key: 'value',
get: function get() {
return this.refs.connected.getWrappedInstance().value;
}
}]);
return FieldArray;
}(_react.Component);
FieldArray.propTypes = {
name: _propTypes2.default.string.isRequired,
component: _propTypes2.default.func.isRequired,
props: _propTypes2.default.object,
validate: _propTypes2.default.oneOfType([_propTypes2.default.func, _propTypes2.default.arrayOf(_propTypes2.default.func)]),
warn: _propTypes2.default.oneOfType([_propTypes2.default.func, _propTypes2.default.arrayOf(_propTypes2.default.func)]),
withRef: _propTypes2.default.bool
};
FieldArray.contextTypes = {
_reduxForm: _propTypes2.default.object
};
return FieldArray;
}n/a
function createFields(_ref) {
var deepEqual = _ref.deepEqual,
getIn = _ref.getIn,
toJS = _ref.toJS,
size = _ref.size;
var ConnectedFields = (0, _ConnectedFields2.default)({
deepEqual: deepEqual,
getIn: getIn,
toJS: toJS,
size: size
});
var Fields = function (_Component) {
_inherits(Fields, _Component);
function Fields(props, context) {
_classCallCheck(this, Fields);
var _this = _possibleConstructorReturn(this, (Fields.__proto__ || Object.getPrototypeOf(Fields)).call(this, props, context
));
if (!context._reduxForm) {
throw new Error('Fields must be inside a component decorated with reduxForm()');
}
return _this;
}
_createClass(Fields, [{
key: 'shouldComponentUpdate',
value: function shouldComponentUpdate(nextProps, nextState) {
return (0, _shallowCompare2.default)(this, nextProps, nextState);
}
}, {
key: 'componentWillMount',
value: function componentWillMount() {
var error = validateNameProp(this.props.names);
if (error) {
throw error;
}
var context = this.context;
var register = context._reduxForm.register;
this.names.forEach(function (name) {
return register(name, 'Field');
});
}
}, {
key: 'componentWillReceiveProps',
value: function componentWillReceiveProps(nextProps) {
if (!_plain2.default.deepEqual(this.props.names, nextProps.names)) {
var context = this.context;
var _context$_reduxForm = context._reduxForm,
register = _context$_reduxForm.register,
unregister = _context$_reduxForm.unregister;
// unregister old name
this.props.names.forEach(function (name) {
return unregister((0, _prefixName2.default)(context, name));
});
// register new name
nextProps.names.forEach(function (name) {
return register((0, _prefixName2.default)(context, name), 'Field');
});
}
}
}, {
key: 'componentWillUnmount',
value: function componentWillUnmount() {
var context = this.context;
var unregister = context._reduxForm.unregister;
this.props.names.forEach(function (name) {
return unregister((0, _prefixName2.default)(context, name));
});
}
}, {
key: 'getRenderedComponent',
value: function getRenderedComponent() {
(0, _invariant2.default)(this.props.withRef, 'If you want to access getRenderedComponent(), ' + 'you must specify a withRef
prop to Fields');
return this.refs.connected.getWrappedInstance().getRenderedComponent();
}
}, {
key: 'render',
value: function render() {
var context = this.context;
return (0, _react.createElement)(ConnectedFields, _extends({}, this.props, {
names: this.props.names.map(function (name) {
return (0, _prefixName2.default)(context, name);
}),
_reduxForm: this.context._reduxForm,
ref: 'connected'
}));
}
}, {
key: 'names',
get: function get() {
var context = this.context;
return this.props.names.map(function (name) {
return (0, _prefixName2.default)(context, name);
});
}
}, {
key: 'dirty',
get: function get() {
return this.refs.connected.getWrappedInstance().isDirty();
}
}, {
key: 'pristine',
get: function get() {
return !this.dirty;
}
}, {
key: 'values',
get: function get() {
return this.refs.connected && this.refs.connected.getWrappedInstance().getValues();
}
}]);
return Fields;
}(_react.Component);
Fields.propTypes = {
names: function names(props, propName) {
return validateNameProp(props[propName]);
},
component: _propTypes2.default.oneOfType([_propTypes2.default.func, _propTypes2.default.string]).isRequired,
format: _propTypes2.default.fun ...n/a
function Form(props, context) {
_classCallCheck(this, Form);
var _this = _possibleConstructorReturn(this, (Form.__proto__ || Object.getPrototypeOf(Form)).call(this, props, context));
if (!context._reduxForm) {
throw new Error('Form must be inside a component decorated with reduxForm()');
}
return _this;
}n/a
function FormSection(props, context) {
_classCallCheck(this, FormSection);
var _this = _possibleConstructorReturn(this, (FormSection.__proto__ || Object.getPrototypeOf(FormSection)).call(this, props, context
));
if (!context._reduxForm) {
throw new Error('FormSection must be inside a component decorated with reduxForm()');
}
return _this;
}n/a
function SubmissionError(errors) {
_classCallCheck(this, SubmissionError);
var _this = _possibleConstructorReturn(this, (SubmissionError.__proto__ || Object.getPrototypeOf(SubmissionError)).call(this, '
Submit Validation Failed'));
_this.errors = errors;
return _this;
}n/a
function arrayInsert(form, field, index, value) {
return { type: _actionTypes.ARRAY_INSERT, meta: { form: form, field: field, index: index }, payload: value };
}n/a
function arrayMove(form, field, from, to) {
return { type: _actionTypes.ARRAY_MOVE, meta: { form: form, field: field, from: from, to: to } };
}n/a
function arrayPop(form, field) {
return { type: _actionTypes.ARRAY_POP, meta: { form: form, field: field } };
}n/a
function arrayPush(form, field, value) {
return { type: _actionTypes.ARRAY_PUSH, meta: { form: form, field: field }, payload: value };
}n/a
function arrayRemove(form, field, index) {
return { type: _actionTypes.ARRAY_REMOVE, meta: { form: form, field: field, index: index } };
}n/a
function arrayRemoveAll(form, field) {
return { type: _actionTypes.ARRAY_REMOVE_ALL, meta: { form: form, field: field } };
}n/a
function arrayShift(form, field) {
return { type: _actionTypes.ARRAY_SHIFT, meta: { form: form, field: field } };
}n/a
function arraySplice(form, field, index, removeNum, value) {
var action = {
type: _actionTypes.ARRAY_SPLICE,
meta: { form: form, field: field, index: index, removeNum: removeNum }
};
if (value !== undefined) {
action.payload = value;
}
return action;
}n/a
function arraySwap(form, field, indexA, indexB) {
if (indexA === indexB) {
throw new Error('Swap indices cannot be equal');
}
if (indexA < 0 || indexB < 0) {
throw new Error('Swap indices cannot be negative');
}
return { type: _actionTypes.ARRAY_SWAP, meta: { form: form, field: field, indexA: indexA, indexB: indexB } };
}n/a
function arrayUnshift(form, field, value) {
return { type: _actionTypes.ARRAY_UNSHIFT, meta: { form: form, field: field }, payload: value };
}n/a
function autofill(form, field, value) {
return { type: _actionTypes.AUTOFILL, meta: { form: form, field: field }, payload: value };
}n/a
function blur(form, field, value, touch) {
return { type: _actionTypes.BLUR, meta: { form: form, field: field, touch: touch }, payload: value };
}...
return event.preventDefault();
}
}), newValue, previousValue);
}
if (!defaultPrevented) {
// dispatch blur action
dispatch(_reduxForm.blur(name, newValue));
// call post-blur callback
if (_reduxForm.asyncValidate) {
_reduxForm.asyncValidate(name, newValue);
}
}
}
...function change(form, field, value, touch, persistentSubmitErrors) {
return { type: _actionTypes.CHANGE, meta: { form: form, field: field, touch: touch, persistentSubmitErrors: persistentSubmitErrors
}, payload: value };
}...
defaultPrevented = true;
return event.preventDefault();
}
}), newValue, previousValue);
}
if (!defaultPrevented) {
// dispatch change action
dispatch(_reduxForm.change(name, newValue));
}
}
}, {
key: 'handleFocus',
value: function handleFocus(event) {
var _props2 = this.props,
name = _props2.name,
...function clearAsyncError(form, field) {
return { type: _actionTypes.CLEAR_ASYNC_ERROR, meta: { form: form, field: field } };
}n/a
function clearSubmit(form) {
return { type: _actionTypes.CLEAR_SUBMIT, meta: { form: form } };
}n/a
function clearSubmitErrors(form) {
return { type: _actionTypes.CLEAR_SUBMIT_ERRORS, meta: { form: form } };
}n/a
function destroy() {
for (var _len = arguments.length, form = Array(_len), _key = 0; _key < _len; _key++) {
form[_key] = arguments[_key];
}
return { type: _actionTypes.DESTROY, meta: { form: form } };
}n/a
function focus(form, field) {
return { type: _actionTypes.FOCUS, meta: { form: form, field: field } };
}...
defaultPrevented = true;
return event.preventDefault();
}
}));
}
if (!defaultPrevented) {
dispatch(_reduxForm.focus(name));
}
}
}, {
key: 'handleBlur',
value: function handleBlur(event) {
var _props3 = this.props,
name = _props3.name,
...function initialize(form, values, keepDirty) {
var otherMeta = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
if (keepDirty instanceof Object) {
otherMeta = keepDirty;
keepDirty = false;
}
return { type: _actionTypes.INITIALIZE, meta: _extends({ form: form, keepDirty: keepDirty }, otherMeta), payload: values };
}...
key: 'initIfNeeded',
value: function initIfNeeded(nextProps) {
var enableReinitialize = this.props.enableReinitialize;
if (nextProps) {
if ((enableReinitialize || !nextProps.initialized) && !deepEqual(this.props.initialValues, nextProps.initialValues
)) {
var keepDirty = nextProps.initialized && this.props.keepDirtyOnReinitialize;
this.props.initialize(nextProps.initialValues, keepDirty);
}
} else if (this.props.initialValues && (!this.props.initialized || enableReinitialize)) {
this.props.initialize(this.props.initialValues, this.props.keepDirtyOnReinitialize);
}
}
}, {
key: 'updateSyncErrorsIfNeeded',
...function registerField(form, name, type) {
return { type: _actionTypes.REGISTER_FIELD, meta: { form: form }, payload: { name: name, type: type } };
}...
key: 'isPristine',
value: function isPristine() {
return this.props.pristine;
}
}, {
key: 'register',
value: function register(name, type, getValidator, getWarner) {
this.props.registerField(name, type);
if (getValidator) {
this.fieldValidators[name] = getValidator;
}
if (getWarner) {
this.fieldWarners[name] = getWarner;
}
}
...function reset(form) {
return { type: _actionTypes.RESET, meta: { form: form } };
}...
return !_this7.submitPromise && _this7.listenToSubmit((0, _handleSubmit2.default)(checkSubmit(submitOrEvent),
_extends({}, _this7.props, (0, _redux.bindActionCreators)({ blur: blur, change: change }, dispatch)), _this7.props.validExceptSubmit
, _this7.asyncValidate, _this7.getFieldList({ excludeFieldArray: true })));
});
}
}
}, {
key: 'reset',
value: function reset() {
this.props.reset();
}
}, {
key: 'render',
value: function render() {
// remove some redux-form config-only props
/* eslint-disable no-unused-vars */
var _props9 = this.props,
...function setSubmitFailed(form) {
for (var _len2 = arguments.length, fields = Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
fields[_key2 - 1] = arguments[_key2];
}
return { type: _actionTypes.SET_SUBMIT_FAILED, meta: { form: form, fields: fields }, error: true };
}n/a
function setSubmitSucceeded(form) {
for (var _len3 = arguments.length, fields = Array(_len3 > 1 ? _len3 - 1 : 0), _key3 = 1; _key3 < _len3; _key3++) {
fields[_key3 - 1] = arguments[_key3];
}
return { type: _actionTypes.SET_SUBMIT_SUCCEEDED, meta: { form: form, fields: fields }, error: false };
}n/a
function startAsyncValidation(form, field) {
return { type: _actionTypes.START_ASYNC_VALIDATION, meta: { form: form, field: field } };
}n/a
function startSubmit(form) {
return { type: _actionTypes.START_SUBMIT, meta: { form: form } };
}n/a
function stopAsyncValidation(form, errors) {
var action = {
type: _actionTypes.STOP_ASYNC_VALIDATION,
meta: { form: form },
payload: errors
};
if (errors && Object.keys(errors).length) {
action.error = true;
}
return action;
}n/a
function stopSubmit(form, errors) {
var action = {
type: _actionTypes.STOP_SUBMIT,
meta: { form: form },
payload: errors
};
if (errors && Object.keys(errors).length) {
action.error = true;
}
return action;
}n/a
function submit(form) {
return { type: _actionTypes.SUBMIT, meta: { form: form } };
}...
value: function submitIfNeeded(nextProps) {
var _props2 = this.props,
clearSubmit = _props2.clearSubmit,
triggerSubmit = _props2.triggerSubmit;
if (!triggerSubmit && nextProps.triggerSubmit) {
clearSubmit();
this.submit();
}
}
}, {
key: 'validateIfNeeded',
value: function validateIfNeeded(nextProps) {
var _props3 = this.props,
shouldValidate = _props3.shouldValidate,
...function touch(form) {
for (var _len4 = arguments.length, fields = Array(_len4 > 1 ? _len4 - 1 : 0), _key4 = 1; _key4 < _len4; _key4++) {
fields[_key4 - 1] = arguments[_key4];
}
return { type: _actionTypes.TOUCH, meta: { form: form, fields: fields } };
}n/a
function unregisterField(form, name) {
var destroyOnUnmount = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
return { type: _actionTypes.UNREGISTER_FIELD, meta: { form: form }, payload: { name: name, destroyOnUnmount: destroyOnUnmount } };
}...
}
}
}, {
key: 'unregister',
value: function unregister(name) {
if (!this.destroyed) {
if (this.props.destroyOnUnmount || this.props.forceUnregisterOnUnmount) {
this.props.unregisterField(name);
delete this.fieldValidators[name];
delete this.fieldWarners[name];
} else {
this.props.unregisterField(name, false);
}
}
}
...function untouch(form) {
for (var _len5 = arguments.length, fields = Array(_len5 > 1 ? _len5 - 1 : 0), _key5 = 1; _key5 < _len5; _key5++) {
fields[_key5 - 1] = arguments[_key5];
}
return { type: _actionTypes.UNTOUCH, meta: { form: form, fields: fields } };
}n/a
function updateSyncErrors(form) {
var syncErrors = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
var error = arguments[2];
return { type: _actionTypes.UPDATE_SYNC_ERRORS, meta: { form: form }, payload: { syncErrors: syncErrors, error: error } };
}n/a
function updateSyncWarnings(form) {
var syncWarnings = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
var warning = arguments[2];
return { type: _actionTypes.UPDATE_SYNC_WARNINGS, meta: { form: form }, payload: { syncWarnings: syncWarnings, warning: warning
} };
}n/a
function asyncValidation(fn, start, stop, field) {
start(field);
var promise = fn();
if (!(0, _isPromise2.default)(promise)) {
throw new Error('asyncValidate function passed to reduxForm must return a promise');
}
var handleErrors = function handleErrors(rejected) {
return function (errors) {
if (errors && Object.keys(errors).length) {
stop(errors);
return errors;
} else if (rejected) {
stop();
throw new Error('Asynchronous validation promise was rejected without errors.');
}
stop();
return Promise.resolve();
};
};
return promise.then(handleErrors(false), handleErrors(true));
}n/a
function createAll(structure) {
return _extends({
// separate out field actions
actionTypes: actionTypes
}, actions, {
Field: (0, _Field2.default)(structure),
Fields: (0, _Fields2.default)(structure),
FieldArray: (0, _FieldArray2.default)(structure),
Form: _Form2.default,
FormSection: _FormSection2.default,
formValueSelector: (0, _formValueSelector2.default)(structure),
getFormNames: (0, _getFormNames2.default)(structure),
getFormValues: (0, _getFormValues2.default)(structure),
getFormInitialValues: (0, _getFormInitialValues2.default)(structure),
getFormSyncErrors: (0, _getFormSyncErrors2.default)(structure),
getFormAsyncErrors: (0, _getFormAsyncErrors2.default)(structure),
getFormSyncWarnings: (0, _getFormSyncWarnings2.default)(structure),
getFormSubmitErrors: (0, _getFormSubmitErrors2.default)(structure),
isDirty: (0, _isDirty2.default)(structure),
isInvalid: (0, _isInvalid2.default)(structure),
isPristine: (0, _isPristine2.default)(structure),
isValid: (0, _isValid2.default)(structure),
isSubmitting: (0, _isSubmitting2.default)(structure),
hasSubmitSucceeded: (0, _hasSubmitSucceeded2.default)(structure),
hasSubmitFailed: (0, _hasSubmitFailed2.default)(structure),
propTypes: _propTypes2.default,
reduxForm: (0, _reduxForm2.default)(structure),
reducer: (0, _reducer2.default)(structure),
SubmissionError: _SubmissionError2.default,
values: (0, _values2.default)(structure)
});
}n/a
function createFieldArrayProps(getIn, name, form, sectionPrefix, getValue, _ref) {
var arrayInsert = _ref.arrayInsert,
arrayMove = _ref.arrayMove,
arrayPop = _ref.arrayPop,
arrayPush = _ref.arrayPush,
arrayRemove = _ref.arrayRemove,
arrayRemoveAll = _ref.arrayRemoveAll,
arrayShift = _ref.arrayShift,
arraySplice = _ref.arraySplice,
arraySwap = _ref.arraySwap,
arrayUnshift = _ref.arrayUnshift,
asyncError = _ref.asyncError,
dirty = _ref.dirty,
length = _ref.length,
pristine = _ref.pristine,
submitError = _ref.submitError,
state = _ref.state,
submitFailed = _ref.submitFailed,
submitting = _ref.submitting,
syncError = _ref.syncError,
syncWarning = _ref.syncWarning,
value = _ref.value,
props = _ref.props,
rest = _objectWithoutProperties(_ref, ['arrayInsert', 'arrayMove', 'arrayPop', 'arrayPush', 'arrayRemove', 'arrayRemoveAll
', 'arrayShift', 'arraySplice', 'arraySwap', 'arrayUnshift', 'asyncError', 'dirty', 'length', 'pristine', 'submitError', 'state', '
submitFailed', 'submitting', 'syncError', 'syncWarning', 'value', 'props']);
var error = syncError || asyncError || submitError;
var warning = syncWarning;
var fieldName = sectionPrefix ? name.replace(sectionPrefix + '.', '') : name;
var finalProps = _extends({
fields: {
_isFieldArray: true,
forEach: function forEach(callback) {
return (value || []).forEach(function (item, index) {
return callback(fieldName + '[' + index + ']', index, finalProps.fields);
});
},
get: getValue,
getAll: function getAll() {
return value;
},
insert: arrayInsert,
length: length,
map: function map(callback) {
return (value || []).map(function (item, index) {
return callback(fieldName + '[' + index + ']', index, finalProps.fields);
});
},
move: arrayMove,
name: name,
pop: function pop() {
arrayPop();
return getIn(value, length - 1);
},
push: arrayPush,
reduce: function reduce(callback, initial) {
return (value || []).reduce(function (accumulator, item, index) {
return callback(accumulator, fieldName + '[' + index + ']', index, finalProps.fields);
}, initial);
},
remove: arrayRemove,
removeAll: arrayRemoveAll,
shift: function shift() {
arrayShift();
return getIn(value, 0);
},
swap: arraySwap,
unshift: arrayUnshift
},
meta: {
dirty: dirty,
error: error,
form: form,
warning: warning,
invalid: !!error,
pristine: pristine,
submitting: submitting,
submitFailed: submitFailed,
touched: !!(state && getIn(state, 'touched')),
valid: !error
}
}, props, rest);
return finalProps;
}n/a
function createFieldProps(_ref2, name, _ref) {
var getIn = _ref2.getIn,
toJS = _ref2.toJS;
var asyncError = _ref.asyncError,
asyncValidating = _ref.asyncValidating,
onBlur = _ref.onBlur,
onChange = _ref.onChange,
onDrop = _ref.onDrop,
onDragStart = _ref.onDragStart,
dirty = _ref.dirty,
dispatch = _ref.dispatch,
onFocus = _ref.onFocus,
form = _ref.form,
format = _ref.format,
parse = _ref.parse,
pristine = _ref.pristine,
props = _ref.props,
state = _ref.state,
submitError = _ref.submitError,
submitFailed = _ref.submitFailed,
submitting = _ref.submitting,
syncError = _ref.syncError,
syncWarning = _ref.syncWarning,
validate = _ref.validate,
value = _ref.value,
_value = _ref._value,
warn = _ref.warn,
custom = _objectWithoutProperties(_ref, ['asyncError', 'asyncValidating', 'onBlur', 'onChange', 'onDrop', 'onDragStart', '
dirty', 'dispatch', 'onFocus', 'form', 'format', 'parse', 'pristine', 'props', 'state', 'submitError', 'submitFailed', 'submitting
', 'syncError', 'syncWarning', 'validate', 'value', '_value', 'warn']);
var error = syncError || asyncError || submitError;
var warning = syncWarning;
var formatFieldValue = function formatFieldValue(value, format) {
if (format === null) {
return value;
}
var defaultFormattedValue = value == null ? '' : value;
return format ? format(value, name) : defaultFormattedValue;
};
var formattedFieldValue = formatFieldValue(value, format);
return {
input: processProps(custom.type, {
name: name,
onBlur: onBlur,
onChange: onChange,
onDragStart: onDragStart,
onDrop: onDrop,
onFocus: onFocus,
value: formattedFieldValue
}, _value),
meta: _extends({}, toJS(state), {
active: !!(state && getIn(state, 'active')),
asyncValidating: asyncValidating,
autofilled: !!(state && getIn(state, 'autofilled')),
dirty: dirty,
dispatch: dispatch,
error: error,
form: form,
warning: warning,
invalid: !!error,
pristine: pristine,
submitting: !!submitting,
submitFailed: !!submitFailed,
touched: !!(state && getIn(state, 'touched')),
valid: !error,
visited: !!(state && getIn(state, 'visited'))
}),
custom: _extends({}, custom, props)
};
}n/a
function deepEqual(a, b) {
return (0, _isEqualWith3.default)(a, b, customizer);
}n/a
function defaultShouldAsyncValidate(_ref) {
var initialized = _ref.initialized,
trigger = _ref.trigger,
pristine = _ref.pristine,
syncValidationPasses = _ref.syncValidationPasses;
if (!syncValidationPasses) {
return false;
}
switch (trigger) {
case 'blur':
// blurring
return true;
case 'submit':
// submitting, so only async validate if form is dirty or was never initialized
// conversely, DON'T async validate if the form is pristine just as it was initialized
return !pristine || !initialized;
default:
return false;
}
}n/a
function defaultShouldValidate(_ref) {
var values = _ref.values,
nextProps = _ref.nextProps,
initialRender = _ref.initialRender,
lastFieldValidatorKeys = _ref.lastFieldValidatorKeys,
fieldValidatorKeys = _ref.fieldValidatorKeys,
structure = _ref.structure;
if (initialRender) {
return true;
}
return !structure.deepEqual(values, nextProps.values) || !structure.deepEqual(lastFieldValidatorKeys, fieldValidatorKeys);
}n/a
function deleteIn(state, field) {
return deleteInWithPath.apply(undefined, [state].concat(_toConsumableArray((0, _toPath3.default)(field))));
}n/a
function createDeleteInWithCleanUp(_ref) {
var deepEqual = _ref.deepEqual,
empty = _ref.empty,
getIn = _ref.getIn,
deleteIn = _ref.deleteIn,
setIn = _ref.setIn;
var deleteInWithCleanUp = function deleteInWithCleanUp(state, path) {
if (path[path.length - 1] === ']') {
// array path
var pathTokens = (0, _toPath3.default)(path);
pathTokens.pop();
var parent = getIn(state, pathTokens.join('.'));
return parent ? setIn(state, path, undefined) : state;
}
var result = deleteIn(state, path);
var dotIndex = path.lastIndexOf('.');
if (dotIndex > 0) {
var parentPath = path.substring(0, dotIndex);
if (parentPath[parentPath.length - 1] !== ']') {
var _parent = getIn(result, parentPath);
if (deepEqual(_parent, empty)) {
return deleteInWithCleanUp(result, parentPath);
}
}
}
return result;
};
return deleteInWithCleanUp;
}n/a
function dragStartMock(setData) {
return getEvent({
dataTransfer: { setData: setData }
});
}n/a
function dropMock(getData) {
return getEvent({
dataTransfer: { getData: getData }
});
}n/a
function valueMock(value) {
return getEvent({ target: { value: value } });
}n/a
function createFormValueSelector(_ref) {
var getIn = _ref.getIn;
return function (form) {
var getFormState = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : function (state) {
return getIn(state, 'form');
};
(0, _invariant2.default)(form, 'Form value must be specified');
return function (state) {
for (var _len = arguments.length, fields = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
fields[_key - 1] = arguments[_key];
}
(0, _invariant2.default)(fields.length, 'No fields specified');
return fields.length === 1 ?
// only selecting one field, so return its value
getIn(getFormState(state), form + '.values.' + fields[0]) :
// selecting many fields, so return an object of field values
fields.reduce(function (accumulator, field) {
var value = getIn(getFormState(state), form + '.values.' + field);
return value === undefined ? accumulator : _plain2.default.setIn(accumulator, field, value);
}, {});
};
};
}n/a
function generateValidator(validators, _ref) {
var getIn = _ref.getIn;
return function (values, props) {
var errors = {};
Object.keys(validators).forEach(function (name) {
var value = getIn(values, name);
var error = getError(value, values, props, validators[name]);
if (error) {
errors = _plain2.default.setIn(errors, name, error);
}
});
return errors;
};
}n/a
function getDisplayName(Comp) {
return Comp.displayName || Comp.name || 'Component';
}n/a
function createGetFormAsyncErrors(_ref) {
var getIn = _ref.getIn;
return function (form) {
var getFormState = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : function (state) {
return getIn(state, 'form');
};
return function (state) {
return getIn(getFormState(state), form + '.asyncErrors');
};
};
}n/a
function createGetFormInitialValues(_ref) {
var getIn = _ref.getIn;
return function (form) {
var getFormState = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : function (state) {
return getIn(state, 'form');
};
return function (state) {
return getIn(getFormState(state), form + '.initial');
};
};
}n/a
function createGetFormNames(_ref) {
var getIn = _ref.getIn,
keys = _ref.keys;
return function () {
var getFormState = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : function (state) {
return getIn(state, 'form');
};
return function (state) {
return keys(getFormState(state));
};
};
}n/a
function createGetFormSubmitErrors(_ref) {
var getIn = _ref.getIn;
return function (form) {
var getFormState = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : function (state) {
return getIn(state, 'form');
};
return function (state) {
return getIn(getFormState(state), form + '.submitErrors');
};
};
}n/a
function createGetFormSyncErrors(_ref) {
var getIn = _ref.getIn;
return function (form) {
var getFormState = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : function (state) {
return getIn(state, 'form');
};
return function (state) {
return getIn(getFormState(state), form + '.syncErrors');
};
};
}n/a
function createGetFormSyncWarnings(_ref) {
var getIn = _ref.getIn;
return function (form) {
var getFormState = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : function (state) {
return getIn(state, 'form');
};
return function (state) {
return getIn(getFormState(state), form + '.syncWarnings');
};
};
}n/a
function createGetFormValues(_ref) {
var getIn = _ref.getIn;
return function (form) {
var getFormState = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : function (state) {
return getIn(state, 'form');
};
return function (state) {
return getIn(getFormState(state), form + '.values');
};
};
}n/a
function getIn(state, field) {
if (!state) {
return state;
}
var path = (0, _toPath3.default)(field);
var length = path.length;
if (!length) {
return undefined;
}
var result = state;
for (var i = 0; i < length && !!result; ++i) {
result = result[path[i]];
}
return result;
}n/a
function getValue(event, isReactNative) {
if ((0, _isEvent2.default)(event)) {
if (!isReactNative && event.nativeEvent && event.nativeEvent.text !== undefined) {
return event.nativeEvent.text;
}
if (isReactNative && event.nativeEvent !== undefined) {
return event.nativeEvent.text;
}
var _event$target = event.target,
type = _event$target.type,
value = _event$target.value,
checked = _event$target.checked,
files = _event$target.files,
dataTransfer = event.dataTransfer;
if (type === 'checkbox') {
return checked;
}
if (type === 'file') {
return files || dataTransfer && dataTransfer.files;
}
if (type === 'select-multiple') {
return getSelectedValues(event.target.options);
}
return value;
}
return event;
}n/a
function handleSubmit(submit, props, valid, asyncValidate, fields) {
var dispatch = props.dispatch,
onSubmitFail = props.onSubmitFail,
onSubmitSuccess = props.onSubmitSuccess,
startSubmit = props.startSubmit,
stopSubmit = props.stopSubmit,
setSubmitFailed = props.setSubmitFailed,
setSubmitSucceeded = props.setSubmitSucceeded,
syncErrors = props.syncErrors,
touch = props.touch,
values = props.values,
persistentSubmitErrors = props.persistentSubmitErrors;
touch.apply(undefined, _toConsumableArray(fields)); // mark all fields as touched
if (valid || persistentSubmitErrors) {
var doSubmit = function doSubmit() {
var result = void 0;
try {
result = submit(values, dispatch, props);
} catch (submitError) {
var error = submitError instanceof _SubmissionError2.default ? submitError.errors : undefined;
stopSubmit(error);
setSubmitFailed.apply(undefined, _toConsumableArray(fields));
if (onSubmitFail) {
onSubmitFail(error, dispatch, submitError, props);
}
if (error || onSubmitFail) {
// if you've provided an onSubmitFail callback, don't re-throw the error
return error;
} else {
throw submitError;
}
}
if ((0, _isPromise2.default)(result)) {
startSubmit();
return result.then(function (submitResult) {
stopSubmit();
setSubmitSucceeded();
if (onSubmitSuccess) {
onSubmitSuccess(submitResult, dispatch, props);
}
return submitResult;
}, function (submitError) {
var error = submitError instanceof _SubmissionError2.default ? submitError.errors : undefined;
stopSubmit(error);
setSubmitFailed.apply(undefined, _toConsumableArray(fields));
if (onSubmitFail) {
onSubmitFail(error, dispatch, submitError, props);
}
if (error || onSubmitFail) {
// if you've provided an onSubmitFail callback, don't re-throw the error
return error;
} else {
throw submitError;
}
});
} else {
setSubmitSucceeded();
if (onSubmitSuccess) {
onSubmitSuccess(result, dispatch, props);
}
}
return result;
};
var asyncValidateResult = asyncValidate && asyncValidate();
if (asyncValidateResult) {
return asyncValidateResult.then(function (asyncErrors) {
if (asyncErrors) {
throw asyncErrors;
}
return doSubmit();
}).catch(function (asyncErrors) {
setSubmitFailed.apply(undefined, _toConsumableArray(fields));
if (onSubmitFail) {
onSubmitFail(asyncErrors, dispatch, null, props);
}
return Promise.reject(asyncErrors);
});
} else {
return doSubmit();
}
} else {
setSubmitFailed.apply(undefined, _toConsumableArray(fields));
if (onSubmitFail) {
onSubmitFail(syncErrors, dispatch, null, props);
}
return syncErrors;
}
}n/a
function createHasError(_ref) {
var getIn = _ref.getIn;
var hasError = function hasError(field, syncErrors, asyncErrors, submitErrors) {
if (!syncErrors && !asyncErrors && !submitErrors) {
return false;
}
var name = getIn(field, 'name');
var type = getIn(field, 'type');
return getErrorKeys(name, type).some(function (key) {
return getIn(syncErrors, key) || getIn(asyncErrors, key) || getIn(submitErrors, key);
});
};
return hasError;
}n/a
function createHasSubmitFailed(_ref) {
var getIn = _ref.getIn;
return function (form) {
var getFormState = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : function (state) {
return getIn(state, 'form');
};
return function (state) {
var formState = getFormState(state);
return getIn(formState, form + '.submitFailed') || false;
};
};
}n/a
function createHasSubmitSucceeded(_ref) {
var getIn = _ref.getIn;
return function (form) {
var getFormState = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : function (state) {
return getIn(state, 'form');
};
return function (state) {
var formState = getFormState(state);
return getIn(formState, form + '.submitSucceeded') || false;
};
};
}n/a
function isChecked(value) {
if (typeof value === 'boolean') {
return value;
}
if (typeof value === 'string') {
var lower = value.toLowerCase();
if (lower === 'true') {
return true;
}
if (lower === 'false') {
return false;
}
}
return undefined;
}n/a
function createIsDirty(structure) {
return function (form, getFormState) {
var isPristine = (0, _isPristine2.default)(structure)(form, getFormState);
return function (state) {
return !isPristine(state);
};
};
}n/a
function isEvent(candidate) {
return !!(candidate && candidate.stopPropagation && candidate.preventDefault);
}n/a
function createIsInvalid(structure) {
return function (form, getFormState) {
var isValid = (0, _isValid2.default)(structure)(form, getFormState);
return function (state) {
return !isValid(state);
};
};
}n/a
function createIsPristine(_ref) {
var deepEqual = _ref.deepEqual,
empty = _ref.empty,
getIn = _ref.getIn;
return function (form) {
var getFormState = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : function (state) {
return getIn(state, 'form');
};
return function (state) {
var formState = getFormState(state);
var initial = getIn(formState, form + '.initial') || empty;
var values = getIn(formState, form + '.values') || initial;
return deepEqual(initial, values);
};
};
}n/a
function createIsSubmitting(_ref) {
var getIn = _ref.getIn;
return function (form) {
var getFormState = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : function (state) {
return getIn(state, 'form');
};
return function (state) {
var formState = getFormState(state);
return getIn(formState, form + '.submitting') || false;
};
};
}n/a
function createIsValid(structure) {
var getIn = structure.getIn,
keys = structure.keys;
var hasError = (0, _hasError2.default)(structure);
return function (form) {
var getFormState = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : function (state) {
return getIn(state, 'form');
};
var ignoreSubmitErrors = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
return function (state) {
var formState = getFormState(state);
var syncError = getIn(formState, form + '.syncError');
if (syncError) {
return false;
}
if (!ignoreSubmitErrors) {
var error = getIn(formState, form + '.error');
if (error) {
return false;
}
}
var syncErrors = getIn(formState, form + '.syncErrors');
var asyncErrors = getIn(formState, form + '.asyncErrors');
var submitErrors = ignoreSubmitErrors ? undefined : getIn(formState, form + '.submitErrors');
if (!syncErrors && !asyncErrors && !submitErrors) {
return true;
}
var registeredFields = getIn(formState, form + '.registeredFields');
if (!registeredFields) {
return true;
}
return !keys(registeredFields).filter(function (name) {
return getIn(registeredFields, '[\'' + name + '\'].count') > 0;
}).some(function (name) {
return hasError(getIn(registeredFields, '[\'' + name + '\']'), syncErrors, asyncErrors, submitErrors);
});
};
};
}n/a
function keys(value) {
return value ? Object.keys(value) : [];
}n/a
function onChangeValue(event, _ref) {
var name = _ref.name,
parse = _ref.parse,
normalize = _ref.normalize;
// read value from input
var value = (0, _getValue2.default)(event, _isReactNative2.default);
// parse value if we have a parser
if (parse) {
value = parse(value, name);
}
// normalize value
if (normalize) {
value = normalize(name, value);
}
return value;
}n/a
function formatName(context, name) {
var sectionPrefix = context._reduxForm.sectionPrefix;
return !sectionPrefix ? name : sectionPrefix + "." + name;
}n/a
anyTouched = function () { [native code] }n/a
array = function () { [native code] }n/a
asyncValidate = function () { [native code] }...
if (!defaultPrevented) {
// dispatch blur action
dispatch(_reduxForm.blur(name, newValue));
// call post-blur callback
if (_reduxForm.asyncValidate) {
_reduxForm.asyncValidate(name, newValue);
}
}
}
}, {
key: 'handleDragStart',
value: function handleDragStart(event) {
var _props4 = this.props,
...asyncValidating = function () { [native code] }n/a
autofill = function () { [native code] }n/a
blur = function () { [native code] }...
return event.preventDefault();
}
}), newValue, previousValue);
}
if (!defaultPrevented) {
// dispatch blur action
dispatch(_reduxForm.blur(name, newValue));
// call post-blur callback
if (_reduxForm.asyncValidate) {
_reduxForm.asyncValidate(name, newValue);
}
}
}
...change = function () { [native code] }...
defaultPrevented = true;
return event.preventDefault();
}
}), newValue, previousValue);
}
if (!defaultPrevented) {
// dispatch change action
dispatch(_reduxForm.change(name, newValue));
}
}
}, {
key: 'handleFocus',
value: function handleFocus(event) {
var _props2 = this.props,
name = _props2.name,
...clearAsyncError = function () { [native code] }n/a
clearSubmit = function () { [native code] }n/a
destroy = function () { [native code] }n/a
dirty = function () { [native code] }n/a
dispatch = function () { [native code] }...
Provider,
{ store: store },
React.createElement(DecoratedTestForm, null)
));
expect(onSubmit).toNotHaveBeenCalled();
store.dispatch(submit('testForm'));
expect(onSubmit).toHaveBeenCalled();
expect(onSubmit.calls.length).toBe(1);
expect(onSubmit.calls[0].arguments[0]).toEqualMap({ foo: 42 });
expect(onSubmit.calls[0].arguments[1]).toBeA('function');
expect(onSubmit.calls[0].arguments[2].values).toEqualMap({ foo: 42 });
});
...error = function () { [native code] }...
}
var argIndex = 0;
var message = 'Warning: ' + format.replace(/%s/g, function () {
return args[argIndex++];
});
if (typeof console !== 'undefined') {
console.error(message);
}
try {
// --- Welcome to debugging React ---
// This error was thrown as a convenience so that you can use this stack
// to find the callsite that caused this warning to fire.
throw new Error(message);
} catch (x) {}
...form = function () { [native code] }n/a
handleSubmit = function () { [native code] }...
}
_createClass(TestForm, [{
key: 'render',
value: function render() {
return React.createElement(
Form,
{ onSubmit: this.props.handleSubmit(onSubmit) },
React.createElement(Field, { name: 'foo', component: 'input' })
);
}
}]);
return TestForm;
}(Component);
...initialValues = function () { [native code] }n/a
initialize = function () { [native code] }...
key: 'initIfNeeded',
value: function initIfNeeded(nextProps) {
var enableReinitialize = this.props.enableReinitialize;
if (nextProps) {
if ((enableReinitialize || !nextProps.initialized) && !deepEqual(this.props.initialValues, nextProps.initialValues
)) {
var keepDirty = nextProps.initialized && this.props.keepDirtyOnReinitialize;
this.props.initialize(nextProps.initialValues, keepDirty);
}
} else if (this.props.initialValues && (!this.props.initialized || enableReinitialize)) {
this.props.initialize(this.props.initialValues, this.props.keepDirtyOnReinitialize);
}
}
}, {
key: 'updateSyncErrorsIfNeeded',
...initialized = function () { [native code] }n/a
invalid = function () { [native code] }n/a
pristine = function () { [native code] }n/a
pure = function () { [native code] }n/a
reset = function () { [native code] }...
return !_this7.submitPromise && _this7.listenToSubmit((0, _handleSubmit2.default)(checkSubmit(submitOrEvent),
_extends({}, _this7.props, (0, _redux.bindActionCreators)({ blur: blur, change: change }, dispatch)), _this7.props.validExceptSubmit
, _this7.asyncValidate, _this7.getFieldList({ excludeFieldArray: true })));
});
}
}
}, {
key: 'reset',
value: function reset() {
this.props.reset();
}
}, {
key: 'render',
value: function render() {
// remove some redux-form config-only props
/* eslint-disable no-unused-vars */
var _props9 = this.props,
...submit = function () { [native code] }...
value: function submitIfNeeded(nextProps) {
var _props2 = this.props,
clearSubmit = _props2.clearSubmit,
triggerSubmit = _props2.triggerSubmit;
if (!triggerSubmit && nextProps.triggerSubmit) {
clearSubmit();
this.submit();
}
}
}, {
key: 'validateIfNeeded',
value: function validateIfNeeded(nextProps) {
var _props3 = this.props,
shouldValidate = _props3.shouldValidate,
...submitFailed = function () { [native code] }n/a
submitSucceeded = function () { [native code] }n/a
submitting = function () { [native code] }n/a
touch = function () { [native code] }n/a
triggerSubmit = function () { [native code] }n/a
untouch = function () { [native code] }n/a
valid = function () { [native code] }n/a
warning = function () { [native code] }n/a
array = function () { [native code] }n/a
isRequired = function () { [native code] }n/a
error = function () { [native code] }...
}
var argIndex = 0;
var message = 'Warning: ' + format.replace(/%s/g, function () {
return args[argIndex++];
});
if (typeof console !== 'undefined') {
console.error(message);
}
try {
// --- Welcome to debugging React ---
// This error was thrown as a convenience so that you can use this stack
// to find the callsite that caused this warning to fire.
throw new Error(message);
} catch (x) {}
...isRequired = function () { [native code] }n/a
initialValues = function () { [native code] }n/a
isRequired = function () { [native code] }n/a
triggerSubmit = function () { [native code] }n/a
isRequired = function () { [native code] }n/a
reducer = function () {
var state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : empty;
var action = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
var form = action && action.meta && action.meta.form;
if (!form || !isReduxFormAction(action)) {
return state;
}
if (action.type === _actionTypes.DESTROY) {
return action.meta.form.reduce(function (result, form) {
return deleteInWithCleanUp(result, form);
}, state);
}
var formState = getIn(state, form);
var result = reducer(formState, action);
return result === formState ? state : setIn(state, form, result);
}n/a
function plugin(reducers) {
var _this = this;
// use 'function' keyword to enable 'this'
return decorate(function () {
var state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : empty;
var action = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
return Object.keys(reducers).reduce(function (accumulator, key) {
var previousState = getIn(accumulator, key);
var nextState = reducers[key](previousState, action, getIn(state, key));
return nextState === previousState ? accumulator : setIn(accumulator, key, nextState);
}, _this(state, action));
});
}n/a
function createReduxForm(structure) {
var deepEqual = structure.deepEqual,
empty = structure.empty,
getIn = structure.getIn,
setIn = structure.setIn,
keys = structure.keys,
fromJS = structure.fromJS;
var isValid = (0, _isValid2.default)(structure);
return function (initialConfig) {
var config = _extends({
touchOnBlur: true,
touchOnChange: false,
persistentSubmitErrors: false,
destroyOnUnmount: true,
shouldAsyncValidate: _defaultShouldAsyncValidate2.default,
shouldValidate: _defaultShouldValidate2.default,
enableReinitialize: false,
keepDirtyOnReinitialize: false,
getFormState: function getFormState(state) {
return getIn(state, 'form');
},
pure: true,
forceUnregisterOnUnmount: false
}, initialConfig);
return function (WrappedComponent) {
var Form = function (_Component) {
_inherits(Form, _Component);
function Form(props) {
_classCallCheck(this, Form);
var _this = _possibleConstructorReturn(this, (Form.__proto__ || Object.getPrototypeOf(Form)).call(this, props));
_this.submit = _this.submit.bind(_this);
_this.reset = _this.reset.bind(_this);
_this.asyncValidate = _this.asyncValidate.bind(_this);
_this.getValues = _this.getValues.bind(_this);
_this.register = _this.register.bind(_this);
_this.unregister = _this.unregister.bind(_this);
_this.submitCompleted = _this.submitCompleted.bind(_this);
_this.submitFailed = _this.submitFailed.bind(_this);
_this.fieldValidators = {};
_this.lastFieldValidatorKeys = [];
_this.fieldWarners = {};
_this.lastFieldWarnerKeys = [];
return _this;
}
_createClass(Form, [{
key: 'getChildContext',
value: function getChildContext() {
var _this2 = this;
return {
_reduxForm: _extends({}, this.props, {
getFormState: function getFormState(state) {
return getIn(_this2.props.getFormState(state), _this2.props.form);
},
asyncValidate: this.asyncValidate,
getValues: this.getValues,
sectionPrefix: undefined,
register: this.register,
unregister: this.unregister,
registerInnerOnSubmit: function registerInnerOnSubmit(innerOnSubmit) {
return _this2.innerOnSubmit = innerOnSubmit;
}
})
};
}
}, {
key: 'initIfNeeded',
value: function initIfNeeded(nextProps) {
var enableReinitialize = this.props.enableReinitialize;
if (nextProps) {
if ((enableReinitialize || !nextProps.initialized) && !deepEqual(this.props.initialValues, nextProps.initialValues
)) {
var keepDirty = nextProps.initialized && this.props.keepDirtyOnReinitialize;
this.props.initialize(nextProps.initialValues, keepDirty);
}
} else if (this.props.initialValues && (!this.props.initialized || enableReinitialize)) {
this.props.initialize(this.props.initialValues, this.props.keepDirtyOnReinitialize);
}
}
}, {
key: 'updateSyncErrorsIfNeeded',
value: function updateSyncErrorsIfNeeded(nextSyncErrors, nextError) {
var _props = this.props,
error = _props.error,
updateSyncErrors = _props.updateSyncErrors;
var noErrors = (!this.lastSyncErrors || !Object.keys(this.lastSyncErrors).length) && !error;
var nextNoErrors = (!nextSyncErrors || !Object.keys(nextSyncErrors).length) && !nextError;
if (!(noErrors && nextNoErrors) && (!_plain2.default.deepEqual(this.lastSyncErrors, nextSyncErrors) || !_plain2.default
.deepEqual(error, nextError))) {
this.lastSyncErrors = nextSyncErrors;
updateSyncErrors( ...n/a
function setIn(state, field, value) {
return setInWithPath(state, value, (0, _toPath3.default)(field), 0);
}n/a
function shallowCompare(instance, nextProps, nextState) {
return !(0, _isEqualWith3.default)(instance.props, nextProps, customizer) || !(0, _isEqualWith3.default)(instance.state, nextState
, customizer);
}n/a
function silenceEvent(event) {
var is = (0, _isEvent2.default)(event);
if (is) {
event.preventDefault();
}
return is;
}n/a
function silenceEvents(fn) {
return function (event) {
for (var _len = arguments.length, args = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
args[_key - 1] = arguments[_key];
}
return (0, _silenceEvent2.default)(event) ? fn.apply(undefined, args) : fn.apply(undefined, [event].concat(args));
};
}n/a
function splice(array, index, removeNum, value) {
array = array || [];
if (index < array.length) {
if (value === undefined && !removeNum) {
// inserting undefined
var _copy2 = [].concat(_toConsumableArray(array));
_copy2.splice(index, 0, null);
_copy2[index] = undefined;
return _copy2;
}
if (value != null) {
var _copy3 = [].concat(_toConsumableArray(array));
_copy3.splice(index, removeNum, value); // removing and adding
return _copy3;
}
var _copy = [].concat(_toConsumableArray(array));
_copy.splice(index, removeNum); // removing
return _copy;
}
if (removeNum) {
// trying to remove non-existant item: return original array
return array;
}
// trying to add outside of range: just set value
var copy = [].concat(_toConsumableArray(array));
copy[index] = value;
return copy;
}n/a
function createValues(_ref) {
var getIn = _ref.getIn;
return function (config) {
var _prop$getFormState$co = _extends({
prop: 'values',
getFormState: function getFormState(state) {
return getIn(state, 'form');
}
}, config),
form = _prop$getFormState$co.form,
prop = _prop$getFormState$co.prop,
getFormState = _prop$getFormState$co.getFormState;
return (0, _reactRedux.connect)(function (state) {
return _defineProperty({}, prop, getIn(getFormState(state), form + '.values'));
}, function () {
return {};
} // ignore dispatch
);
};
}n/a