@experium/findy-form 1.3.27 → 1.3.29

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -98,6 +98,17 @@ var styles = {
98
98
  "timeIndicator": "index__timeIndicator",
99
99
  "modalButtonGroup": "index__modalButtonGroup"
100
100
  };
101
+ var OPD_FIELD = 'personalDataAgreement';
102
+ var OPD_DATA_CHECKBOX = {
103
+ 'accept': true,
104
+ 'acceptCheckbox': true,
105
+ 'value': true
106
+ };
107
+ var OPD_DATA_CHECKBOXES = {
108
+ 'purposeCheckbox': 'purpose',
109
+ 'mailingCheckbox': 'mailing',
110
+ 'transmissionCheckbox': 'transmission'
111
+ };
101
112
 
102
113
  var getInitialValues = function getInitialValues(initialValues, fields, captchaOptions) {
103
114
  var values = initialValues || {};
@@ -205,6 +216,17 @@ var Form = /*#__PURE__*/function (_Component) {
205
216
  submitted: true
206
217
  });
207
218
 
219
+ if ((0, _ramda.equals)(values[OPD_FIELD], true) && !values[OPD_FIELD].value) {
220
+ values[OPD_FIELD] = OPD_DATA_CHECKBOX;
221
+ }
222
+
223
+ (0, _ramda.mapObjIndexed)(function (value, name) {
224
+ if (OPD_DATA_CHECKBOXES[name]) {
225
+ values[OPD_FIELD][name] = value;
226
+ values[OPD_FIELD][OPD_DATA_CHECKBOXES[name]] = value;
227
+ }
228
+ }, values);
229
+
208
230
  _this.props.onSubmit(values, _objectSpread(_objectSpread({}, _this.formProps), {}, {
209
231
  reset: _this.reset
210
232
  }));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@experium/findy-form",
3
- "version": "1.3.27",
3
+ "version": "1.3.29",
4
4
  "main": "./lib/index.js",
5
5
  "homepage": "https://experium.github.io/findy-form",
6
6
  "repository": "https://github.com/experium/findy-form",
@@ -5,7 +5,7 @@ import i18n from '../utils/i18n';
5
5
 
6
6
  import React, { Component } from 'react';
7
7
  import { Form as FinalFormForm, Field, FormSpy } from 'react-final-form';
8
- import { head, pathOr, prop, equals, isEmpty, forEach, path, includes, assocPath } from 'ramda';
8
+ import { head, pathOr, prop, equals, isEmpty, forEach, path, includes, assocPath, mapObjIndexed } from 'ramda';
9
9
  import arrayMutators from 'final-form-arrays';
10
10
  import { withTranslation } from 'react-i18next';
11
11
  import cx from 'classnames';
@@ -23,6 +23,18 @@ import Fields from './Fields';
23
23
  import Spinner from './formComponents/Spinner';
24
24
  import Captcha from './formComponents/Captcha';
25
25
 
26
+ const OPD_FIELD = 'personalDataAgreement';
27
+ const OPD_DATA_CHECKBOX = {
28
+ 'accept': true,
29
+ 'acceptCheckbox': true,
30
+ 'value': true,
31
+ };
32
+ const OPD_DATA_CHECKBOXES = {
33
+ 'purposeCheckbox': 'purpose',
34
+ 'mailingCheckbox': 'mailing',
35
+ 'transmissionCheckbox': 'transmission',
36
+ };
37
+
26
38
  const getInitialValues = (initialValues, fields, captchaOptions) => {
27
39
  let values = initialValues || {};
28
40
 
@@ -156,6 +168,18 @@ class Form extends Component {
156
168
 
157
169
  onSubmit = values => {
158
170
  this.setState({ submitted: true });
171
+
172
+ if (equals(values[OPD_FIELD], true) && !values[OPD_FIELD].value) {
173
+ values[OPD_FIELD] = OPD_DATA_CHECKBOX;
174
+ }
175
+
176
+ mapObjIndexed((value, name) => {
177
+ if (OPD_DATA_CHECKBOXES[name]) {
178
+ values[OPD_FIELD][name] = value;
179
+ values[OPD_FIELD][OPD_DATA_CHECKBOXES[name]] = value;
180
+ }
181
+ }, values);
182
+
159
183
  this.props.onSubmit(values, { ...this.formProps, reset: this.reset });
160
184
  };
161
185