UNPKG

cosmo-ui

Version:
25 lines 1.02 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var constants_1 = require("../constants"); var actions_1 = require("../actions"); exports.validateForm = function (action$, store) { return action$.ofType(constants_1.SUBMIT_FORM) .map(function (action) { var data = action.data; // if no data is provided get the data from the state if (!data) { data = store.getState().forms[action.formName]; } var keys = Object.keys(data); for (var _i = 0, keys_1 = keys; _i < keys_1.length; _i++) { var field = keys_1[_i]; if (data[field] && !data[field].valid) { // dispatch an action to say the form is invalid return actions_1.formInvalid(action.formName, data, action.args); } } // dispatch an action to say the form is valid return actions_1.formValid(action.formName, data, action.args); }); }; //# sourceMappingURL=forms.js.map