UNPKG

react-redux-formal

Version:

Form state management and building library for react and redux

90 lines (80 loc) 2.78 kB
'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); exports.fieldUpdate = fieldUpdate; exports.fieldValidateSuccess = fieldValidateSuccess; exports.fieldValidateFailure = fieldValidateFailure; exports.formAddField = formAddField; exports.formInit = formInit; exports.formReset = formReset; var _formConstants = require('./formConstants'); var c = _interopRequireWildcard(_formConstants); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } } /** * Update value of field * * @param {String} formName - Name of the form the field belongs to * @param {String} fieldName - Name of the field * @param {Mixed} value - The value to validate * * @return {Object} - The action */ function fieldUpdate(formName, fieldName, value) { return { type: c.FIELD_UPDATE_VALUE, formName: formName, fieldName: fieldName, value: value }; } /** * Mark a field's validation as successful * * @param {String} formName - Name of the form the field belongs to * @param {String} fieldName - Name of the field * * @return {Object} - The action */ function fieldValidateSuccess(formName, fieldName) { return { type: c.FIELD_VALIDATE_SUCCESS, formName: formName, fieldName: fieldName }; } /** * Mark a field's validation as failed * * @param {String} formName - Name of the form the field belongs to * @param {String} fieldName - Name of the field * @param {String} error - The error raised by the validator * * @return {Object} - The action */ function fieldValidateFailure(formName, fieldName, error) { return { type: c.FIELD_VALIDATE_FAILURE, formName: formName, fieldName: fieldName, error: error }; } /** * Add a new field to a form * * @param {String} formName - Form to add field to * @param {String} fieldName - Name of the field to add * @param {Mixed} value - Initial value of the field */ function formAddField(formName, fieldName, value) { return { type: c.FORM_ADD_FIELD, formName: formName, fieldName: fieldName, value: value }; } /** * Initialize a form * * @param {String} formName - Form to initialise * @param {Object} fields - Form fields * @param {Object} values - Form values * * @return {Object} - The action */ function formInit(formName, fields, values) { return { type: c.FORM_INIT, formName: formName, fields: fields, values: values }; } /** * Reset a form's values back to its initial values * * @param {String} formName - Form to reset * * @return {Object} - The action */ function formReset(formName) { return { type: c.FORM_RESET, formName: formName }; }