Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

redux-form

Package Overview
Dependencies
Maintainers
1
Versions
236
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

redux-form - npm Package Compare versions

Comparing version 6.2.0 to 6.2.1

18

es/__tests__/createFieldArrayProps.spec.js

@@ -199,5 +199,5 @@ var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };

expect(callback.calls.length).toBe(3);
expect(callback.calls[0].arguments).toEqual(['foo[0]', 0]);
expect(callback.calls[1].arguments).toEqual(['foo[1]', 1]);
expect(callback.calls[2].arguments).toEqual(['foo[2]', 2]);
expect(callback.calls[0].arguments).toEqual(['foo[0]', 0, result.fields]);
expect(callback.calls[1].arguments).toEqual(['foo[1]', 1, result.fields]);
expect(callback.calls[2].arguments).toEqual(['foo[2]', 2, result.fields]);
});

@@ -222,5 +222,5 @@

expect(callback.calls.length).toBe(3);
expect(callback.calls[0].arguments).toEqual(['foo[0]', 0]);
expect(callback.calls[1].arguments).toEqual(['foo[1]', 1]);
expect(callback.calls[2].arguments).toEqual(['foo[2]', 2]);
expect(callback.calls[0].arguments).toEqual(['foo[0]', 0, result.fields]);
expect(callback.calls[1].arguments).toEqual(['foo[1]', 1, result.fields]);
expect(callback.calls[2].arguments).toEqual(['foo[2]', 2, result.fields]);
});

@@ -245,10 +245,10 @@

expect(callback.calls.length).toBe(3);
expect(callback.calls[0].arguments).toEqual([{}, 'foo[0]', 0]);
expect(callback.calls[0].arguments).toEqual([{}, 'foo[0]', 0, result.fields]);
expect(callback.calls[1].arguments).toEqual([{
'foo[0]': { whatever: true, name: 'foo[0]' }
}, 'foo[1]', 1]);
}, 'foo[1]', 1, result.fields]);
expect(callback.calls[2].arguments).toEqual([{
'foo[0]': { whatever: true, name: 'foo[0]' },
'foo[1]': { whatever: true, name: 'foo[1]' }
}, 'foo[2]', 2]);
}, 'foo[2]', 2, result.fields]);
});

@@ -255,0 +255,0 @@

@@ -342,2 +342,11 @@ import { createSpy } from 'expect';

});
it('should not format value when format prop is null', function () {
var result = createFieldProps(getIn, 'foo', {
state: empty,
value: null,
format: null
});
expect(result.input.value).toBe(null);
});
});

@@ -344,0 +353,0 @@ };

@@ -19,2 +19,3 @@ var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();

import createField from '../Field';
import createFields from '../Fields';
import createFieldArray from '../FieldArray';

@@ -31,2 +32,3 @@ import FormSection from '../FormSection';

var Field = createField(structure);
var Fields = createFields(structure);
var FieldArray = createFieldArray(structure);

@@ -120,2 +122,74 @@ var reducer = createReducer(structure);

it('should update Fields values at the right depth', function () {
var store = makeStore({
testForm: {
values: {
foo: {
bar: '42',
baz: '100'
}
}
}
});
var input = createSpy(function (props) {
return React.createElement('input', props.bar.input);
}).andCallThrough();
var Form = function (_Component2) {
_inherits(Form, _Component2);
function Form() {
_classCallCheck(this, Form);
return _possibleConstructorReturn(this, (Form.__proto__ || Object.getPrototypeOf(Form)).apply(this, arguments));
}
_createClass(Form, [{
key: 'render',
value: function render() {
return React.createElement(
FormSection,
{ name: 'foo' },
React.createElement(Fields, { names: ['bar', 'baz'], component: input })
);
}
}]);
return Form;
}(Component);
var TestForm = reduxForm({ form: 'testForm' })(Form);
TestUtils.renderIntoDocument(React.createElement(
Provider,
{ store: store },
React.createElement(TestForm, null)
));
// input displaying string value
expect(input.calls.length).toBe(1);
expect(input.calls[0].arguments[0].bar.input.value).toBe('42');
expect(input.calls[0].arguments[0].baz.input.value).toBe('100');
// update value
input.calls[0].arguments[0].bar.input.onChange('15');
// input displaying updated string value
expect(input.calls.length).toBe(2);
expect(input.calls[1].arguments[0].bar.input.value).toBe('15');
expect(store.getState()).toEqualMap({
form: {
testForm: {
values: {
foo: {
bar: '15',
baz: '100'
}
},
registeredFields: [{ name: 'foo.bar', type: 'Field' }, { name: 'foo.baz', type: 'Field' }]
}
}
});
});
it('should update FieldArray values at the right depth', function () {

@@ -160,4 +234,4 @@ var store = makeStore({

var Form = function (_Component2) {
_inherits(Form, _Component2);
var Form = function (_Component3) {
_inherits(Form, _Component3);

@@ -164,0 +238,0 @@ function Form() {

@@ -130,3 +130,6 @@ import _noop from 'lodash-es/noop';

expect(stopSubmit).toNotHaveBeenCalled();
expect(onSubmitFail).toHaveBeenCalled().toHaveBeenCalledWith(values, dispatch);
expect(onSubmitFail).toHaveBeenCalled();
expect(onSubmitFail.calls[0].arguments[0]).toEqual(values);
expect(onSubmitFail.calls[0].arguments[1]).toEqual(dispatch);
expect(onSubmitFail.calls[0].arguments[2]).toBe(null);
expect(touch).toHaveBeenCalled().toHaveBeenCalledWith('foo', 'baz');

@@ -133,0 +136,0 @@ expect(setSubmitSucceeded).toNotHaveBeenCalled();

import expect from 'expect';
import * as expectedActionTypes from '../actionTypes';
import expectedPropTypes from '../propTypes';
import { actionTypes, arrayInsert, arrayMove, arrayPop, arrayPush, arrayRemove, arrayRemoveAll, arrayShift, arraySplice, arraySwap, arrayUnshift, autofill, blur, change, destroy, Field, FieldArray, FormSection, focus, formValueSelector, initialize, propTypes, reducer, reduxForm, reset, setSubmitFailed, setSubmitSucceeded, startAsyncValidation, startSubmit, stopAsyncValidation, stopSubmit, SubmissionError, touch, untouch, values } from '../index';
import { actionTypes, arrayInsert, arrayMove, arrayPop, arrayPush, arrayRemove, arrayRemoveAll, arrayShift, arraySplice, arraySwap, arrayUnshift, autofill, blur, change, destroy, Field, FieldArray, FormSection, focus, formValueSelector, initialize, propTypes, reducer, reduxForm, registerField, reset, setSubmitFailed, setSubmitSucceeded, startAsyncValidation, startSubmit, stopAsyncValidation, stopSubmit, SubmissionError, touch, unregisterField, untouch, values } from '../index';

@@ -79,2 +79,5 @@ describe('index', function () {

});
it('should export registerField', function () {
expect(registerField).toExist().toBeA('function');
});
it('should export reset', function () {

@@ -107,2 +110,5 @@ expect(reset).toExist().toBeA('function');

});
it('should export unregisterField', function () {
expect(unregisterField).toExist().toBeA('function');
});
it('should export untouch', function () {

@@ -109,0 +115,0 @@ expect(untouch).toExist().toBeA('function');

@@ -230,2 +230,35 @@ import { initialize } from '../actions';

});
it('should persist warnings if they exist', function () {
var state = reducer(fromJS({
foo: {
registeredFields: [{ name: 'myField', type: 'Field' }],
values: {
myField: 'newValue'
},
initial: {
myField: 'initialValue'
},
warning: 'form wide warning',
syncWarnings: {
myField: 'field warning'
}
}
}), initialize('foo', { myField: 'newValue' }, true));
expect(state).toEqualMap({
foo: {
registeredFields: [{ name: 'myField', type: 'Field' }],
values: {
myField: 'newValue'
},
initial: {
myField: 'newValue'
},
warning: 'form wide warning',
syncWarnings: {
myField: 'field warning'
}
}
});
});
};

@@ -232,0 +265,0 @@ };

@@ -1,31 +0,31 @@

export var ARRAY_INSERT = 'redux-form/ARRAY_INSERT';
export var ARRAY_MOVE = 'redux-form/ARRAY_MOVE';
export var ARRAY_POP = 'redux-form/ARRAY_POP';
export var ARRAY_PUSH = 'redux-form/ARRAY_PUSH';
export var ARRAY_REMOVE = 'redux-form/ARRAY_REMOVE';
export var ARRAY_REMOVE_ALL = 'redux-form/ARRAY_REMOVE_ALL';
export var ARRAY_SHIFT = 'redux-form/ARRAY_SHIFT';
export var ARRAY_SPLICE = 'redux-form/ARRAY_SPLICE';
export var ARRAY_UNSHIFT = 'redux-form/ARRAY_UNSHIFT';
export var ARRAY_SWAP = 'redux-form/ARRAY_SWAP';
export var AUTOFILL = 'redux-form/AUTOFILL';
export var BLUR = 'redux-form/BLUR';
export var CHANGE = 'redux-form/CHANGE';
export var CLEAR_SUBMIT = 'redux-form/CLEAR_SUBMIT';
export var DESTROY = 'redux-form/DESTROY';
export var FOCUS = 'redux-form/FOCUS';
export var INITIALIZE = 'redux-form/INITIALIZE';
export var REGISTER_FIELD = 'redux-form/REGISTER_FIELD';
export var RESET = 'redux-form/RESET';
export var SET_SUBMIT_FAILED = 'redux-form/SET_SUBMIT_FAILED';
export var SET_SUBMIT_SUCCEEDED = 'redux-form/SET_SUBMIT_SUCCEEDED';
export var START_ASYNC_VALIDATION = 'redux-form/START_ASYNC_VALIDATION';
export var START_SUBMIT = 'redux-form/START_SUBMIT';
export var STOP_ASYNC_VALIDATION = 'redux-form/STOP_ASYNC_VALIDATION';
export var STOP_SUBMIT = 'redux-form/STOP_SUBMIT';
export var SUBMIT = 'redux-form/SUBMIT';
export var TOUCH = 'redux-form/TOUCH';
export var UNREGISTER_FIELD = 'redux-form/UNREGISTER_FIELD';
export var UNTOUCH = 'redux-form/UNTOUCH';
export var UPDATE_SYNC_ERRORS = 'redux-form/UPDATE_SYNC_ERRORS';
export var UPDATE_SYNC_WARNINGS = 'redux-form/UPDATE_SYNC_WARNINGS';
export var ARRAY_INSERT = '@@redux-form/ARRAY_INSERT';
export var ARRAY_MOVE = '@@redux-form/ARRAY_MOVE';
export var ARRAY_POP = '@@redux-form/ARRAY_POP';
export var ARRAY_PUSH = '@@redux-form/ARRAY_PUSH';
export var ARRAY_REMOVE = '@@redux-form/ARRAY_REMOVE';
export var ARRAY_REMOVE_ALL = '@@redux-form/ARRAY_REMOVE_ALL';
export var ARRAY_SHIFT = '@@redux-form/ARRAY_SHIFT';
export var ARRAY_SPLICE = '@@redux-form/ARRAY_SPLICE';
export var ARRAY_UNSHIFT = '@@redux-form/ARRAY_UNSHIFT';
export var ARRAY_SWAP = '@@redux-form/ARRAY_SWAP';
export var AUTOFILL = '@@redux-form/AUTOFILL';
export var BLUR = '@@redux-form/BLUR';
export var CHANGE = '@@redux-form/CHANGE';
export var CLEAR_SUBMIT = '@@redux-form/CLEAR_SUBMIT';
export var DESTROY = '@@redux-form/DESTROY';
export var FOCUS = '@@redux-form/FOCUS';
export var INITIALIZE = '@@redux-form/INITIALIZE';
export var REGISTER_FIELD = '@@redux-form/REGISTER_FIELD';
export var RESET = '@@redux-form/RESET';
export var SET_SUBMIT_FAILED = '@@redux-form/SET_SUBMIT_FAILED';
export var SET_SUBMIT_SUCCEEDED = '@@redux-form/SET_SUBMIT_SUCCEEDED';
export var START_ASYNC_VALIDATION = '@@redux-form/START_ASYNC_VALIDATION';
export var START_SUBMIT = '@@redux-form/START_SUBMIT';
export var STOP_ASYNC_VALIDATION = '@@redux-form/STOP_ASYNC_VALIDATION';
export var STOP_SUBMIT = '@@redux-form/STOP_SUBMIT';
export var SUBMIT = '@@redux-form/SUBMIT';
export var TOUCH = '@@redux-form/TOUCH';
export var UNREGISTER_FIELD = '@@redux-form/UNREGISTER_FIELD';
export var UNTOUCH = '@@redux-form/UNTOUCH';
export var UPDATE_SYNC_ERRORS = '@@redux-form/UPDATE_SYNC_ERRORS';
export var UPDATE_SYNC_WARNINGS = '@@redux-form/UPDATE_SYNC_WARNINGS';

@@ -95,3 +95,4 @@ var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };

change = _reduxForm.change,
focus = _reduxForm.focus;
focus = _reduxForm.focus,
sectionPrefix = _reduxForm.sectionPrefix;

@@ -110,3 +111,4 @@ var _Object$keys$reduce = Object.keys(_fields).reduce(function (accumulator, name) {

accumulator.custom = custom;
return plain.setIn(accumulator, name, fieldProps);
var fieldName = sectionPrefix ? name.replace(sectionPrefix + '.', '') : name;
return plain.setIn(accumulator, fieldName, fieldProps);
}, {}),

@@ -113,0 +115,0 @@ custom = _Object$keys$reduce.custom,

@@ -32,3 +32,3 @@ var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };

var warning = syncWarning;
return _extends({
var finalProps = _extends({
fields: {

@@ -38,3 +38,3 @@ _isFieldArray: true,

return (value || []).forEach(function (item, index) {
return callback(name + '[' + index + ']', index);
return callback(name + '[' + index + ']', index, finalProps.fields);
});

@@ -46,3 +46,3 @@ },

return (value || []).map(function (item, index) {
return callback(name + '[' + index + ']', index);
return callback(name + '[' + index + ']', index, finalProps.fields);
});

@@ -59,3 +59,3 @@ },

return (value || []).reduce(function (accumulator, item, index) {
return callback(accumulator, name + '[' + index + ']', index);
return callback(accumulator, name + '[' + index + ']', index, finalProps.fields);
}, initial);

@@ -83,4 +83,5 @@ },

}, props, rest);
return finalProps;
};
export default createFieldArrayProps;

@@ -80,4 +80,13 @@ import _noop from 'lodash-es/noop';

});
var fieldValue = value == null ? '' : value;
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 {

@@ -94,3 +103,3 @@ input: processProps(custom.type, {

onChange: onChange,
onDragStart: createOnDragStart(name, fieldValue),
onDragStart: createOnDragStart(name, formattedFieldValue),
onDrop: createOnDrop(name, boundChange),

@@ -100,3 +109,3 @@ onFocus: createOnFocus(name, function () {

}),
value: format ? format(fieldValue, name) : fieldValue
value: formattedFieldValue
}, _value),

@@ -103,0 +112,0 @@ meta: _extends({}, state, {

@@ -39,3 +39,3 @@ var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };

if (onSubmitFail) {
onSubmitFail(error, dispatch);
onSubmitFail(error, dispatch, submitError);
}

@@ -63,3 +63,3 @@ if (error || onSubmitFail) {

if (onSubmitFail) {
onSubmitFail(error, dispatch);
onSubmitFail(error, dispatch, submitError);
}

@@ -93,3 +93,3 @@ if (error || onSubmitFail) {

if (onSubmitFail) {
onSubmitFail(asyncErrors, dispatch);
onSubmitFail(asyncErrors, dispatch, null);
}

@@ -110,3 +110,3 @@ return Promise.reject(asyncErrors);

if (onSubmitFail) {
onSubmitFail(syncErrors, dispatch);
onSubmitFail(syncErrors, dispatch, null);
}

@@ -113,0 +113,0 @@ return syncErrors;

@@ -38,2 +38,3 @@ import createAll from './createAll';

reduxForm = _createAll.reduxForm,
registerField = _createAll.registerField,
reset = _createAll.reset,

@@ -49,4 +50,5 @@ setSubmitFailed = _createAll.setSubmitFailed,

touch = _createAll.touch,
unregisterField = _createAll.unregisterField,
untouch = _createAll.untouch,
values = _createAll.values;
export { actionTypes, arrayInsert, arrayMove, arrayPop, arrayPush, arrayRemove, arrayRemoveAll, arrayShift, arraySplice, arraySwap, arrayUnshift, blur, autofill, change, destroy, Field, Fields, FieldArray, FormSection, focus, formValueSelector, getFormValues, getFormSyncErrors, getFormSubmitErrors, initialize, isDirty, isInvalid, isPristine, isValid, propTypes, reducer, reduxForm, reset, setSubmitFailed, setSubmitSucceeded, startAsyncValidation, startSubmit, stopAsyncValidation, stopSubmit, submit, SubmissionError, touch, untouch, values };
export { actionTypes, arrayInsert, arrayMove, arrayPop, arrayPush, arrayRemove, arrayRemoveAll, arrayShift, arraySplice, arraySwap, arrayUnshift, blur, autofill, change, destroy, Field, Fields, FieldArray, FormSection, focus, formValueSelector, getFormValues, getFormSyncErrors, getFormSubmitErrors, initialize, isDirty, isInvalid, isPristine, isValid, propTypes, reducer, reduxForm, registerField, reset, setSubmitFailed, setSubmitSucceeded, startAsyncValidation, startSubmit, stopAsyncValidation, stopSubmit, submit, SubmissionError, touch, unregisterField, untouch, values };

@@ -197,2 +197,13 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }

var result = empty; // clean all field state
// persist old warnings, they will get recalculated if the new form values are different from the old values
var warning = getIn(state, 'warning');
if (warning) {
result = setIn(result, 'warning', warning);
}
var syncWarnings = getIn(state, 'syncWarnings');
if (syncWarnings) {
result = setIn(result, 'syncWarnings', syncWarnings);
}
var registeredFields = getIn(state, 'registeredFields');

@@ -199,0 +210,0 @@ if (registeredFields) {

@@ -160,3 +160,3 @@ import _mapValues from 'lodash-es/mapValues';

} else if (this.props.initialValues && (!this.props.initialized || enableReinitialize)) {
this.props.initialize(this.props.initialValues);
this.props.initialize(this.props.initialValues, this.props.keepDirtyOnReinitialize);
}

@@ -334,3 +334,3 @@ }

value: function unregister(name) {
if (!this.destroyed && (!this.unmounted || !instances)) {
if (this.props.destroyOnUnmount && !this.destroyed && (!this.unmounted || !instances)) {
this.props.unregisterField(name);

@@ -572,3 +572,3 @@ }

if (shouldUpdateInitialValues) {
initial = stateInitial;
initial = stateInitial || empty;
}

@@ -575,0 +575,0 @@

@@ -7,13 +7,10 @@ import _toPath from 'lodash-es/toPath';

function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }
var setInWithPath = function setInWithPath(state, value, first) {
for (var _len = arguments.length, rest = Array(_len > 3 ? _len - 3 : 0), _key = 3; _key < _len; _key++) {
rest[_key - 3] = arguments[_key];
var setInWithPath = function setInWithPath(state, value, path, pathIndex) {
if (pathIndex >= path.length) {
return value;
}
if (first === undefined) {
return value;
}
var next = setInWithPath.apply(undefined, [state && state[first], value].concat(rest));
var first = path[pathIndex];
var next = setInWithPath(state && state[first], value, path, pathIndex + 1);
if (!state) {

@@ -24,7 +21,9 @@ var initialized = isNaN(first) ? {} : [];

}
if (Array.isArray(state)) {
var copy = [].concat(_toConsumableArray(state));
var copy = state.slice();
copy[first] = next;
return copy;
}
return _extends({}, state, _defineProperty({}, first, next));

@@ -34,5 +33,5 @@ };

var setIn = function setIn(state, field, value) {
return setInWithPath.apply(undefined, [state, value].concat(_toConsumableArray(_toPath(field))));
return setInWithPath(state, value, _toPath(field), 0);
};
export default setIn;

@@ -221,5 +221,5 @@ 'use strict';

expect(callback.calls.length).toBe(3);
expect(callback.calls[0].arguments).toEqual(['foo[0]', 0]);
expect(callback.calls[1].arguments).toEqual(['foo[1]', 1]);
expect(callback.calls[2].arguments).toEqual(['foo[2]', 2]);
expect(callback.calls[0].arguments).toEqual(['foo[0]', 0, result.fields]);
expect(callback.calls[1].arguments).toEqual(['foo[1]', 1, result.fields]);
expect(callback.calls[2].arguments).toEqual(['foo[2]', 2, result.fields]);
});

@@ -244,5 +244,5 @@

expect(callback.calls.length).toBe(3);
expect(callback.calls[0].arguments).toEqual(['foo[0]', 0]);
expect(callback.calls[1].arguments).toEqual(['foo[1]', 1]);
expect(callback.calls[2].arguments).toEqual(['foo[2]', 2]);
expect(callback.calls[0].arguments).toEqual(['foo[0]', 0, result.fields]);
expect(callback.calls[1].arguments).toEqual(['foo[1]', 1, result.fields]);
expect(callback.calls[2].arguments).toEqual(['foo[2]', 2, result.fields]);
});

@@ -267,10 +267,10 @@

expect(callback.calls.length).toBe(3);
expect(callback.calls[0].arguments).toEqual([{}, 'foo[0]', 0]);
expect(callback.calls[0].arguments).toEqual([{}, 'foo[0]', 0, result.fields]);
expect(callback.calls[1].arguments).toEqual([{
'foo[0]': { whatever: true, name: 'foo[0]' }
}, 'foo[1]', 1]);
}, 'foo[1]', 1, result.fields]);
expect(callback.calls[2].arguments).toEqual([{
'foo[0]': { whatever: true, name: 'foo[0]' },
'foo[1]': { whatever: true, name: 'foo[1]' }
}, 'foo[2]', 2]);
}, 'foo[2]', 2, result.fields]);
});

@@ -277,0 +277,0 @@

@@ -364,2 +364,11 @@ 'use strict';

});
it('should not format value when format prop is null', function () {
var result = (0, _createFieldProps2.default)(getIn, 'foo', {
state: empty,
value: null,
format: null
});
expect(result.input.value).toBe(null);
});
});

@@ -366,0 +375,0 @@ };

@@ -33,2 +33,6 @@ 'use strict';

var _Fields = require('../Fields');
var _Fields2 = _interopRequireDefault(_Fields);
var _FieldArray = require('../FieldArray');

@@ -74,2 +78,3 @@

var Field = (0, _Field2.default)(structure);
var Fields = (0, _Fields2.default)(structure);
var FieldArray = (0, _FieldArray2.default)(structure);

@@ -163,2 +168,74 @@ var reducer = (0, _reducer2.default)(structure);

it('should update Fields values at the right depth', function () {
var store = makeStore({
testForm: {
values: {
foo: {
bar: '42',
baz: '100'
}
}
}
});
var input = (0, _expect.createSpy)(function (props) {
return _react2.default.createElement('input', props.bar.input);
}).andCallThrough();
var Form = function (_Component2) {
_inherits(Form, _Component2);
function Form() {
_classCallCheck(this, Form);
return _possibleConstructorReturn(this, (Form.__proto__ || Object.getPrototypeOf(Form)).apply(this, arguments));
}
_createClass(Form, [{
key: 'render',
value: function render() {
return _react2.default.createElement(
_FormSection2.default,
{ name: 'foo' },
_react2.default.createElement(Fields, { names: ['bar', 'baz'], component: input })
);
}
}]);
return Form;
}(_react.Component);
var TestForm = reduxForm({ form: 'testForm' })(Form);
_reactAddonsTestUtils2.default.renderIntoDocument(_react2.default.createElement(
_reactRedux.Provider,
{ store: store },
_react2.default.createElement(TestForm, null)
));
// input displaying string value
expect(input.calls.length).toBe(1);
expect(input.calls[0].arguments[0].bar.input.value).toBe('42');
expect(input.calls[0].arguments[0].baz.input.value).toBe('100');
// update value
input.calls[0].arguments[0].bar.input.onChange('15');
// input displaying updated string value
expect(input.calls.length).toBe(2);
expect(input.calls[1].arguments[0].bar.input.value).toBe('15');
expect(store.getState()).toEqualMap({
form: {
testForm: {
values: {
foo: {
bar: '15',
baz: '100'
}
},
registeredFields: [{ name: 'foo.bar', type: 'Field' }, { name: 'foo.baz', type: 'Field' }]
}
}
});
});
it('should update FieldArray values at the right depth', function () {

@@ -203,4 +280,4 @@ var store = makeStore({

var Form = function (_Component2) {
_inherits(Form, _Component2);
var Form = function (_Component3) {
_inherits(Form, _Component3);

@@ -207,0 +284,0 @@ function Form() {

@@ -144,3 +144,6 @@ 'use strict';

(0, _expect2.default)(stopSubmit).toNotHaveBeenCalled();
(0, _expect2.default)(onSubmitFail).toHaveBeenCalled().toHaveBeenCalledWith(values, dispatch);
(0, _expect2.default)(onSubmitFail).toHaveBeenCalled();
(0, _expect2.default)(onSubmitFail.calls[0].arguments[0]).toEqual(values);
(0, _expect2.default)(onSubmitFail.calls[0].arguments[1]).toEqual(dispatch);
(0, _expect2.default)(onSubmitFail.calls[0].arguments[2]).toBe(null);
(0, _expect2.default)(touch).toHaveBeenCalled().toHaveBeenCalledWith('foo', 'baz');

@@ -147,0 +150,0 @@ (0, _expect2.default)(setSubmitSucceeded).toNotHaveBeenCalled();

@@ -94,2 +94,5 @@ 'use strict';

});
it('should export registerField', function () {
(0, _expect2.default)(_index.registerField).toExist().toBeA('function');
});
it('should export reset', function () {

@@ -122,2 +125,5 @@ (0, _expect2.default)(_index.reset).toExist().toBeA('function');

});
it('should export unregisterField', function () {
(0, _expect2.default)(_index.unregisterField).toExist().toBeA('function');
});
it('should export untouch', function () {

@@ -124,0 +130,0 @@ (0, _expect2.default)(_index.untouch).toExist().toBeA('function');

@@ -236,2 +236,35 @@ 'use strict';

});
it('should persist warnings if they exist', function () {
var state = reducer(fromJS({
foo: {
registeredFields: [{ name: 'myField', type: 'Field' }],
values: {
myField: 'newValue'
},
initial: {
myField: 'initialValue'
},
warning: 'form wide warning',
syncWarnings: {
myField: 'field warning'
}
}
}), (0, _actions.initialize)('foo', { myField: 'newValue' }, true));
expect(state).toEqualMap({
foo: {
registeredFields: [{ name: 'myField', type: 'Field' }],
values: {
myField: 'newValue'
},
initial: {
myField: 'newValue'
},
warning: 'form wide warning',
syncWarnings: {
myField: 'field warning'
}
}
});
});
};

@@ -238,0 +271,0 @@ };

@@ -6,32 +6,32 @@ 'use strict';

});
var ARRAY_INSERT = exports.ARRAY_INSERT = 'redux-form/ARRAY_INSERT';
var ARRAY_MOVE = exports.ARRAY_MOVE = 'redux-form/ARRAY_MOVE';
var ARRAY_POP = exports.ARRAY_POP = 'redux-form/ARRAY_POP';
var ARRAY_PUSH = exports.ARRAY_PUSH = 'redux-form/ARRAY_PUSH';
var ARRAY_REMOVE = exports.ARRAY_REMOVE = 'redux-form/ARRAY_REMOVE';
var ARRAY_REMOVE_ALL = exports.ARRAY_REMOVE_ALL = 'redux-form/ARRAY_REMOVE_ALL';
var ARRAY_SHIFT = exports.ARRAY_SHIFT = 'redux-form/ARRAY_SHIFT';
var ARRAY_SPLICE = exports.ARRAY_SPLICE = 'redux-form/ARRAY_SPLICE';
var ARRAY_UNSHIFT = exports.ARRAY_UNSHIFT = 'redux-form/ARRAY_UNSHIFT';
var ARRAY_SWAP = exports.ARRAY_SWAP = 'redux-form/ARRAY_SWAP';
var AUTOFILL = exports.AUTOFILL = 'redux-form/AUTOFILL';
var BLUR = exports.BLUR = 'redux-form/BLUR';
var CHANGE = exports.CHANGE = 'redux-form/CHANGE';
var CLEAR_SUBMIT = exports.CLEAR_SUBMIT = 'redux-form/CLEAR_SUBMIT';
var DESTROY = exports.DESTROY = 'redux-form/DESTROY';
var FOCUS = exports.FOCUS = 'redux-form/FOCUS';
var INITIALIZE = exports.INITIALIZE = 'redux-form/INITIALIZE';
var REGISTER_FIELD = exports.REGISTER_FIELD = 'redux-form/REGISTER_FIELD';
var RESET = exports.RESET = 'redux-form/RESET';
var SET_SUBMIT_FAILED = exports.SET_SUBMIT_FAILED = 'redux-form/SET_SUBMIT_FAILED';
var SET_SUBMIT_SUCCEEDED = exports.SET_SUBMIT_SUCCEEDED = 'redux-form/SET_SUBMIT_SUCCEEDED';
var START_ASYNC_VALIDATION = exports.START_ASYNC_VALIDATION = 'redux-form/START_ASYNC_VALIDATION';
var START_SUBMIT = exports.START_SUBMIT = 'redux-form/START_SUBMIT';
var STOP_ASYNC_VALIDATION = exports.STOP_ASYNC_VALIDATION = 'redux-form/STOP_ASYNC_VALIDATION';
var STOP_SUBMIT = exports.STOP_SUBMIT = 'redux-form/STOP_SUBMIT';
var SUBMIT = exports.SUBMIT = 'redux-form/SUBMIT';
var TOUCH = exports.TOUCH = 'redux-form/TOUCH';
var UNREGISTER_FIELD = exports.UNREGISTER_FIELD = 'redux-form/UNREGISTER_FIELD';
var UNTOUCH = exports.UNTOUCH = 'redux-form/UNTOUCH';
var UPDATE_SYNC_ERRORS = exports.UPDATE_SYNC_ERRORS = 'redux-form/UPDATE_SYNC_ERRORS';
var UPDATE_SYNC_WARNINGS = exports.UPDATE_SYNC_WARNINGS = 'redux-form/UPDATE_SYNC_WARNINGS';
var ARRAY_INSERT = exports.ARRAY_INSERT = '@@redux-form/ARRAY_INSERT';
var ARRAY_MOVE = exports.ARRAY_MOVE = '@@redux-form/ARRAY_MOVE';
var ARRAY_POP = exports.ARRAY_POP = '@@redux-form/ARRAY_POP';
var ARRAY_PUSH = exports.ARRAY_PUSH = '@@redux-form/ARRAY_PUSH';
var ARRAY_REMOVE = exports.ARRAY_REMOVE = '@@redux-form/ARRAY_REMOVE';
var ARRAY_REMOVE_ALL = exports.ARRAY_REMOVE_ALL = '@@redux-form/ARRAY_REMOVE_ALL';
var ARRAY_SHIFT = exports.ARRAY_SHIFT = '@@redux-form/ARRAY_SHIFT';
var ARRAY_SPLICE = exports.ARRAY_SPLICE = '@@redux-form/ARRAY_SPLICE';
var ARRAY_UNSHIFT = exports.ARRAY_UNSHIFT = '@@redux-form/ARRAY_UNSHIFT';
var ARRAY_SWAP = exports.ARRAY_SWAP = '@@redux-form/ARRAY_SWAP';
var AUTOFILL = exports.AUTOFILL = '@@redux-form/AUTOFILL';
var BLUR = exports.BLUR = '@@redux-form/BLUR';
var CHANGE = exports.CHANGE = '@@redux-form/CHANGE';
var CLEAR_SUBMIT = exports.CLEAR_SUBMIT = '@@redux-form/CLEAR_SUBMIT';
var DESTROY = exports.DESTROY = '@@redux-form/DESTROY';
var FOCUS = exports.FOCUS = '@@redux-form/FOCUS';
var INITIALIZE = exports.INITIALIZE = '@@redux-form/INITIALIZE';
var REGISTER_FIELD = exports.REGISTER_FIELD = '@@redux-form/REGISTER_FIELD';
var RESET = exports.RESET = '@@redux-form/RESET';
var SET_SUBMIT_FAILED = exports.SET_SUBMIT_FAILED = '@@redux-form/SET_SUBMIT_FAILED';
var SET_SUBMIT_SUCCEEDED = exports.SET_SUBMIT_SUCCEEDED = '@@redux-form/SET_SUBMIT_SUCCEEDED';
var START_ASYNC_VALIDATION = exports.START_ASYNC_VALIDATION = '@@redux-form/START_ASYNC_VALIDATION';
var START_SUBMIT = exports.START_SUBMIT = '@@redux-form/START_SUBMIT';
var STOP_ASYNC_VALIDATION = exports.STOP_ASYNC_VALIDATION = '@@redux-form/STOP_ASYNC_VALIDATION';
var STOP_SUBMIT = exports.STOP_SUBMIT = '@@redux-form/STOP_SUBMIT';
var SUBMIT = exports.SUBMIT = '@@redux-form/SUBMIT';
var TOUCH = exports.TOUCH = '@@redux-form/TOUCH';
var UNREGISTER_FIELD = exports.UNREGISTER_FIELD = '@@redux-form/UNREGISTER_FIELD';
var UNTOUCH = exports.UNTOUCH = '@@redux-form/UNTOUCH';
var UPDATE_SYNC_ERRORS = exports.UPDATE_SYNC_ERRORS = '@@redux-form/UPDATE_SYNC_ERRORS';
var UPDATE_SYNC_WARNINGS = exports.UPDATE_SYNC_WARNINGS = '@@redux-form/UPDATE_SYNC_WARNINGS';

@@ -110,3 +110,4 @@ 'use strict';

change = _reduxForm.change,
focus = _reduxForm.focus;
focus = _reduxForm.focus,
sectionPrefix = _reduxForm.sectionPrefix;

@@ -125,3 +126,4 @@ var _Object$keys$reduce = Object.keys(_fields).reduce(function (accumulator, name) {

accumulator.custom = custom;
return _plain2.default.setIn(accumulator, name, fieldProps);
var fieldName = sectionPrefix ? name.replace(sectionPrefix + '.', '') : name;
return _plain2.default.setIn(accumulator, fieldName, fieldProps);
}, {}),

@@ -128,0 +130,0 @@ custom = _Object$keys$reduce.custom,

@@ -38,3 +38,3 @@ 'use strict';

var warning = syncWarning;
return _extends({
var finalProps = _extends({
fields: {

@@ -44,3 +44,3 @@ _isFieldArray: true,

return (value || []).forEach(function (item, index) {
return callback(name + '[' + index + ']', index);
return callback(name + '[' + index + ']', index, finalProps.fields);
});

@@ -52,3 +52,3 @@ },

return (value || []).map(function (item, index) {
return callback(name + '[' + index + ']', index);
return callback(name + '[' + index + ']', index, finalProps.fields);
});

@@ -65,3 +65,3 @@ },

return (value || []).reduce(function (accumulator, item, index) {
return callback(accumulator, name + '[' + index + ']', index);
return callback(accumulator, name + '[' + index + ']', index, finalProps.fields);
}, initial);

@@ -89,4 +89,5 @@ },

}, props, rest);
return finalProps;
};
exports.default = createFieldArrayProps;

@@ -103,4 +103,13 @@ 'use strict';

});
var fieldValue = value == null ? '' : value;
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 {

@@ -117,3 +126,3 @@ input: processProps(custom.type, {

onChange: onChange,
onDragStart: (0, _createOnDragStart2.default)(name, fieldValue),
onDragStart: (0, _createOnDragStart2.default)(name, formattedFieldValue),
onDrop: (0, _createOnDrop2.default)(name, boundChange),

@@ -123,3 +132,3 @@ onFocus: (0, _createOnFocus2.default)(name, function () {

}),
value: format ? format(fieldValue, name) : fieldValue
value: formattedFieldValue
}, _value),

@@ -126,0 +135,0 @@ meta: _extends({}, state, {

@@ -52,3 +52,3 @@ 'use strict';

if (onSubmitFail) {
onSubmitFail(error, dispatch);
onSubmitFail(error, dispatch, submitError);
}

@@ -76,3 +76,3 @@ if (error || onSubmitFail) {

if (onSubmitFail) {
onSubmitFail(error, dispatch);
onSubmitFail(error, dispatch, submitError);
}

@@ -106,3 +106,3 @@ if (error || onSubmitFail) {

if (onSubmitFail) {
onSubmitFail(asyncErrors, dispatch);
onSubmitFail(asyncErrors, dispatch, null);
}

@@ -123,3 +123,3 @@ return Promise.reject(asyncErrors);

if (onSubmitFail) {
onSubmitFail(syncErrors, dispatch);
onSubmitFail(syncErrors, dispatch, null);
}

@@ -126,0 +126,0 @@ return syncErrors;

@@ -6,3 +6,3 @@ 'use strict';

});
exports.values = exports.untouch = exports.touch = exports.SubmissionError = exports.submit = exports.stopSubmit = exports.stopAsyncValidation = exports.startSubmit = exports.startAsyncValidation = exports.setSubmitSucceeded = exports.setSubmitFailed = exports.reset = exports.reduxForm = exports.reducer = exports.propTypes = exports.isValid = exports.isPristine = exports.isInvalid = exports.isDirty = exports.initialize = exports.getFormSubmitErrors = exports.getFormSyncErrors = exports.getFormValues = exports.formValueSelector = exports.focus = exports.FormSection = exports.FieldArray = exports.Fields = exports.Field = exports.destroy = exports.change = exports.autofill = exports.blur = exports.arrayUnshift = exports.arraySwap = exports.arraySplice = exports.arrayShift = exports.arrayRemoveAll = exports.arrayRemove = exports.arrayPush = exports.arrayPop = exports.arrayMove = exports.arrayInsert = exports.actionTypes = undefined;
exports.values = exports.untouch = exports.unregisterField = exports.touch = exports.SubmissionError = exports.submit = exports.stopSubmit = exports.stopAsyncValidation = exports.startSubmit = exports.startAsyncValidation = exports.setSubmitSucceeded = exports.setSubmitFailed = exports.reset = exports.registerField = exports.reduxForm = exports.reducer = exports.propTypes = exports.isValid = exports.isPristine = exports.isInvalid = exports.isDirty = exports.initialize = exports.getFormSubmitErrors = exports.getFormSyncErrors = exports.getFormValues = exports.formValueSelector = exports.focus = exports.FormSection = exports.FieldArray = exports.Fields = exports.Field = exports.destroy = exports.change = exports.autofill = exports.blur = exports.arrayUnshift = exports.arraySwap = exports.arraySplice = exports.arrayShift = exports.arrayRemoveAll = exports.arrayRemove = exports.arrayPush = exports.arrayPop = exports.arrayMove = exports.arrayInsert = exports.actionTypes = undefined;

@@ -53,2 +53,3 @@ var _createAll2 = require('./createAll');

reduxForm = _createAll.reduxForm,
registerField = _createAll.registerField,
reset = _createAll.reset,

@@ -64,2 +65,3 @@ setSubmitFailed = _createAll.setSubmitFailed,

touch = _createAll.touch,
unregisterField = _createAll.unregisterField,
untouch = _createAll.untouch,

@@ -99,2 +101,3 @@ values = _createAll.values;

exports.reduxForm = reduxForm;
exports.registerField = registerField;
exports.reset = reset;

@@ -110,3 +113,4 @@ exports.setSubmitFailed = setSubmitFailed;

exports.touch = touch;
exports.unregisterField = unregisterField;
exports.untouch = untouch;
exports.values = values;

@@ -209,2 +209,13 @@ 'use strict';

var result = empty; // clean all field state
// persist old warnings, they will get recalculated if the new form values are different from the old values
var warning = getIn(state, 'warning');
if (warning) {
result = setIn(result, 'warning', warning);
}
var syncWarnings = getIn(state, 'syncWarnings');
if (syncWarnings) {
result = setIn(result, 'syncWarnings', syncWarnings);
}
var registeredFields = getIn(state, 'registeredFields');

@@ -211,0 +222,0 @@ if (registeredFields) {

@@ -209,3 +209,3 @@ 'use strict';

} else if (this.props.initialValues && (!this.props.initialized || enableReinitialize)) {
this.props.initialize(this.props.initialValues);
this.props.initialize(this.props.initialValues, this.props.keepDirtyOnReinitialize);
}

@@ -383,3 +383,3 @@ }

value: function unregister(name) {
if (!this.destroyed && (!this.unmounted || !instances)) {
if (this.props.destroyOnUnmount && !this.destroyed && (!this.unmounted || !instances)) {
this.props.unregisterField(name);

@@ -621,3 +621,3 @@ }

if (shouldUpdateInitialValues) {
initial = stateInitial;
initial = stateInitial || empty;
}

@@ -624,0 +624,0 @@

@@ -17,13 +17,10 @@ 'use strict';

function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }
var setInWithPath = function setInWithPath(state, value, first) {
for (var _len = arguments.length, rest = Array(_len > 3 ? _len - 3 : 0), _key = 3; _key < _len; _key++) {
rest[_key - 3] = arguments[_key];
var setInWithPath = function setInWithPath(state, value, path, pathIndex) {
if (pathIndex >= path.length) {
return value;
}
if (first === undefined) {
return value;
}
var next = setInWithPath.apply(undefined, [state && state[first], value].concat(rest));
var first = path[pathIndex];
var next = setInWithPath(state && state[first], value, path, pathIndex + 1);
if (!state) {

@@ -34,7 +31,9 @@ var initialized = isNaN(first) ? {} : [];

}
if (Array.isArray(state)) {
var copy = [].concat(_toConsumableArray(state));
var copy = state.slice();
copy[first] = next;
return copy;
}
return _extends({}, state, _defineProperty({}, first, next));

@@ -44,5 +43,5 @@ };

var setIn = function setIn(state, field, value) {
return setInWithPath.apply(undefined, [state, value].concat(_toConsumableArray((0, _toPath3.default)(field))));
return setInWithPath(state, value, (0, _toPath3.default)(field), 0);
};
exports.default = setIn;
{
"name": "redux-form",
"version": "6.2.0",
"version": "6.2.1",
"description": "A higher order component decorator for forms using Redux and React",

@@ -5,0 +5,0 @@ "main": "./lib/index.js",

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc