@experium/findy-form 1.3.5 → 1.3.7

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.
@@ -401,6 +401,7 @@ var Fields = /*#__PURE__*/function (_Component) {
401
401
  company = _this$props2.company,
402
402
  language = _this$props2.language,
403
403
  languageOrigin = _this$props2.languageOrigin,
404
+ pdaLanguage = _this$props2.pdaLanguage,
404
405
  components = _this$props2.components,
405
406
  htmlOpd = _this$props2.htmlOpd,
406
407
  htmlOpdStyles = _this$props2.htmlOpdStyles,
@@ -438,6 +439,7 @@ var Fields = /*#__PURE__*/function (_Component) {
438
439
  opdSettings: opdSettings,
439
440
  company: company,
440
441
  language: language,
442
+ pdaLanguage: pdaLanguage,
441
443
  languageOrigin: languageOrigin,
442
444
  validate: validateField,
443
445
  getDictionary: _this.getDictionary,
@@ -252,11 +252,13 @@ var Form = /*#__PURE__*/function (_Component) {
252
252
 
253
253
  handleSubmit(e);
254
254
  });
255
+ var pdaLanguage = props.pdaLanguage || props.language || _translations.RU;
255
256
 
256
- var _language = props.language || _translations.RU;
257
+ var _language = (0, _ramda.head)((props.language || _translations.RU).split('-'));
257
258
 
258
259
  _this.state = {
259
260
  language: _language,
261
+ pdaLanguage: pdaLanguage,
260
262
  dictionaries: {},
261
263
  errors: {},
262
264
  initialValues: getInitialValues(props.initialValues, props.fields, props.captchaOptions),
@@ -285,10 +287,12 @@ var Form = /*#__PURE__*/function (_Component) {
285
287
  value: function render() {
286
288
  var _this2 = this;
287
289
 
290
+ var _this$state = this.state,
291
+ language = _this$state.language,
292
+ pdaLanguage = _this$state.pdaLanguage;
288
293
  var _this$props3 = this.props,
289
294
  fields = _this$props3.fields,
290
295
  company = _this$props3.company,
291
- language = _this$props3.language,
292
296
  opdSubmitDisabled = _this$props3.opdSubmitDisabled,
293
297
  formRender = _this$props3.formRender,
294
298
  t = _this$props3.t,
@@ -381,6 +385,7 @@ var Form = /*#__PURE__*/function (_Component) {
381
385
  fieldsWithoutValidation: _this2.state.fieldsWithoutValidation,
382
386
  errors: _this2.state.errors,
383
387
  language: language,
388
+ pdaLanguage: pdaLanguage,
384
389
  languageOrigin: _this2.props.languageOrigin,
385
390
  customValidation: customValidation,
386
391
  updateOpdValuesOn: updateOpdValuesOn,
@@ -429,6 +434,7 @@ var Form = /*#__PURE__*/function (_Component) {
429
434
  dictionaryOptions: {},
430
435
  components: {},
431
436
  language: _translations.RU,
437
+ pdaLanguage: _translations.RU,
432
438
  opdSubmitDisabled: true,
433
439
  excludeDictionary: {},
434
440
  renameDictionary: {},
@@ -85,21 +85,21 @@ var styles = {
85
85
  "modalButtonGroup": "index__modalButtonGroup"
86
86
  };
87
87
 
88
- var getConstructorOpd = function getConstructorOpd(opdSettings, language) {
88
+ var getConstructorOpd = function getConstructorOpd(opdSettings, pdaLanguage, language) {
89
89
  var opdConstructor = (0, _ramda.pathOr)([], ['data', 'opdConstructor'], opdSettings);
90
90
  var text = (opdConstructor || []).reduce(function (res, cur) {
91
91
  switch (cur.type) {
92
92
  case 'question':
93
- return "".concat(res, "<input name=\"").concat(cur.question, "\" placeholder=\"").concat(cur.placeholder || '', "\" type=\"text\" ").concat(cur.required ? 'required' : '', " /> ");
93
+ return "".concat(res, "<input name=\"").concat(cur.question, "\" placeholder=\"").concat((0, _ramda.path)(['translations', language], cur) || cur.placeholder || '', "\" type=\"text\" ").concat(cur.required ? 'required' : '', " /> ");
94
94
 
95
95
  case 'formated':
96
- return res + (cur.text || '');
96
+ return res + ((0, _ramda.path)(['translations', pdaLanguage], cur) || cur.text || '');
97
97
 
98
98
  case 'checkbox':
99
- return "".concat(res, "<div>\n <input type=\"checkbox\" id=\"", "checkbox-".concat(cur.id), "\" ").concat(cur.required ? 'required="required"' : '', " />\n <label for=\"", "checkbox-".concat(cur.id), "\">").concat(cur.label || '', "</label>\n </div>");
99
+ return "".concat(res, "<div>\n <input type=\"checkbox\" id=\"", "checkbox-".concat(cur.id), "\" ").concat(cur.required ? 'required="required"' : '', " />\n <label for=\"", "checkbox-".concat(cur.id), "\">").concat((0, _ramda.path)(['translations', pdaLanguage], cur) || cur.label || '', "</label>\n </div>");
100
100
 
101
101
  case 'opdCheckbox':
102
- return "".concat(res, "<div>\n <input type=\"checkbox\" id=\"").concat(cur.opdType, "\" name=\"").concat(cur.opdType, "\" data-separate-field=\"").concat(cur.opdType, "\" ").concat((0, _ramda.path)([cur.opdType, 'required'], opdSettings) ? 'required="required"' : '', " />\n <label for=\"").concat(cur.opdType, "\">").concat((0, _ramda.pathOr)('', [cur.opdType, 'label'], opdSettings), "</label>\n </div>");
102
+ return "".concat(res, "<div>\n <input type=\"checkbox\" id=\"").concat(cur.opdType, "\" name=\"").concat(cur.opdType, "\" data-separate-field=\"").concat(cur.opdType, "\" ").concat((0, _ramda.path)([cur.opdType, 'required'], opdSettings) ? 'required="required"' : '', " />\n <label for=\"").concat(cur.opdType, "\">").concat((0, _ramda.pathOr)('', [cur.opdType, 'translations', language], opdSettings) || (0, _ramda.pathOr)('', [cur.opdType, 'label'], opdSettings), "</label>\n </div>");
103
103
 
104
104
  default:
105
105
  return res;
@@ -216,7 +216,7 @@ var PersonalDataAgreementComponent = /*#__PURE__*/function (_Component) {
216
216
  return {};
217
217
  });
218
218
  (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "isHtmlOpd", function () {
219
- var constructorOpd = (0, _ramda.path)(['useConstructor'], _this.props.opdSettings) ? getConstructorOpd(_this.props.opdSettings, _this.props.language) : null;
219
+ var constructorOpd = (0, _ramda.path)(['useConstructor'], _this.props.opdSettings) ? getConstructorOpd(_this.props.opdSettings, _this.props.pdaLanguage, _this.props.language) : null;
220
220
  return !!(_this.props.htmlOpd || constructorOpd);
221
221
  });
222
222
  return _this;
@@ -229,9 +229,10 @@ var PersonalDataAgreementComponent = /*#__PURE__*/function (_Component) {
229
229
 
230
230
  var _this$props3 = this.props,
231
231
  opdSettings = _this$props3.opdSettings,
232
+ pdaLanguage = _this$props3.pdaLanguage,
232
233
  language = _this$props3.language;
233
234
  var isHtmlOpd = this.isHtmlOpd();
234
- var constructorOpd = (0, _ramda.path)(['useConstructor'], opdSettings) ? getConstructorOpd(opdSettings, language) : null;
235
+ var constructorOpd = (0, _ramda.path)(['useConstructor'], opdSettings) ? getConstructorOpd(opdSettings, pdaLanguage, language) : null;
235
236
  return /*#__PURE__*/_react["default"].createElement(_FormContext.FormContext.Consumer, null, function (_ref) {
236
237
  var htmlAttrs = _ref.htmlAttrs;
237
238
  return /*#__PURE__*/_react["default"].createElement(_react.Fragment, null, /*#__PURE__*/_react["default"].createElement(_Checkbox.Checkbox, (0, _extends2["default"])({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@experium/findy-form",
3
- "version": "1.3.5",
3
+ "version": "1.3.7",
4
4
  "main": "./lib/index.js",
5
5
  "homepage": "https://experium.github.io/findy-form",
6
6
  "repository": "https://github.com/experium/findy-form",
@@ -237,6 +237,7 @@ class Fields extends Component {
237
237
  company,
238
238
  language,
239
239
  languageOrigin,
240
+ pdaLanguage,
240
241
  components,
241
242
  htmlOpd,
242
243
  htmlOpdStyles,
@@ -267,6 +268,7 @@ class Fields extends Component {
267
268
  opdSettings={opdSettings}
268
269
  company={company}
269
270
  language={language}
271
+ pdaLanguage={pdaLanguage}
270
272
  languageOrigin={languageOrigin}
271
273
  validate={validateField}
272
274
  getDictionary={this.getDictionary}
@@ -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 { pathOr, prop, equals, isEmpty, forEach, path, includes, assocPath } from 'ramda';
8
+ import { head, pathOr, prop, equals, isEmpty, forEach, path, includes, assocPath } from 'ramda';
9
9
  import arrayMutators from 'final-form-arrays';
10
10
  import { withTranslation } from 'react-i18next';
11
11
  import cx from 'classnames';
@@ -45,6 +45,7 @@ class Form extends Component {
45
45
  dictionaryOptions: {},
46
46
  components: {},
47
47
  language: RU,
48
+ pdaLanguage: RU,
48
49
  opdSubmitDisabled: true,
49
50
  excludeDictionary: {},
50
51
  renameDictionary: {},
@@ -58,10 +59,12 @@ class Form extends Component {
58
59
  constructor(props) {
59
60
  super(props);
60
61
 
61
- const language = props.language || RU;
62
+ const pdaLanguage = props.pdaLanguage || props.language || RU;
63
+ const language = head((props.language || RU).split('-'));
62
64
 
63
65
  this.state = {
64
66
  language,
67
+ pdaLanguage,
65
68
  dictionaries: {},
66
69
  errors: {},
67
70
  initialValues: getInitialValues(props.initialValues, props.fields, props.captchaOptions),
@@ -194,10 +197,13 @@ class Form extends Component {
194
197
  }
195
198
 
196
199
  render() {
200
+ const {
201
+ language,
202
+ pdaLanguage,
203
+ } = this.state;
197
204
  const {
198
205
  fields,
199
206
  company,
200
- language,
201
207
  opdSubmitDisabled,
202
208
  formRender,
203
209
  t,
@@ -270,6 +276,7 @@ class Form extends Component {
270
276
  fieldsWithoutValidation={this.state.fieldsWithoutValidation}
271
277
  errors={this.state.errors}
272
278
  language={language}
279
+ pdaLanguage={pdaLanguage}
273
280
  languageOrigin={this.props.languageOrigin}
274
281
  customValidation={customValidation}
275
282
  updateOpdValuesOn={updateOpdValuesOn}
@@ -10,24 +10,24 @@ import HtmlOpdForm, { HtmlOpdFormClear } from './HtmlOpdForm';
10
10
  import { FormContext } from '../../context/FormContext';
11
11
  import { getAttrs } from '../../utils/attrs';
12
12
 
13
- const getConstructorOpd = (opdSettings, language) => {
13
+ const getConstructorOpd = (opdSettings, pdaLanguage, language) => {
14
14
  const opdConstructor = pathOr([], ['data', 'opdConstructor'], opdSettings);
15
15
 
16
16
  const text = (opdConstructor || []).reduce((res, cur) => {
17
17
  switch (cur.type) {
18
18
  case 'question':
19
- return `${res}<input name="${cur.question}" placeholder="${cur.placeholder || ''}" type="text" ${cur.required ? 'required' : ''} /> `;
19
+ return `${res}<input name="${cur.question}" placeholder="${path(['translations', language], cur) || cur.placeholder || ''}" type="text" ${cur.required ? 'required' : ''} /> `;
20
20
  case 'formated':
21
- return res + (cur.text || '');
21
+ return res + (path(['translations', pdaLanguage], cur) || cur.text || '');
22
22
  case 'checkbox':
23
23
  return `${res}<div>
24
24
  <input type="checkbox" id="${`checkbox-${cur.id}`}" ${cur.required ? 'required="required"' : ''} />
25
- <label for="${`checkbox-${cur.id}`}">${cur.label || ''}</label>
25
+ <label for="${`checkbox-${cur.id}`}">${path(['translations', pdaLanguage], cur) || cur.label || ''}</label>
26
26
  </div>`;
27
27
  case 'opdCheckbox':
28
28
  return `${res}<div>
29
29
  <input type="checkbox" id="${cur.opdType}" name="${cur.opdType}" data-separate-field="${cur.opdType}" ${path([cur.opdType, 'required'], opdSettings) ? 'required="required"' : ''} />
30
- <label for="${cur.opdType}">${pathOr('', [cur.opdType, 'label'], opdSettings)}</label>
30
+ <label for="${cur.opdType}">${pathOr('', [cur.opdType, 'translations', language], opdSettings) || pathOr('', [cur.opdType, 'label'], opdSettings)}</label>
31
31
  </div>`;
32
32
  default:
33
33
  return res;
@@ -140,14 +140,14 @@ class PersonalDataAgreementComponent extends Component {
140
140
  }
141
141
 
142
142
  isHtmlOpd = () => {
143
- const constructorOpd = path(['useConstructor'], this.props.opdSettings) ? getConstructorOpd(this.props.opdSettings, this.props.language) : null;
143
+ const constructorOpd = path(['useConstructor'], this.props.opdSettings) ? getConstructorOpd(this.props.opdSettings, this.props.pdaLanguage, this.props.language) : null;
144
144
  return !!(this.props.htmlOpd || constructorOpd);
145
145
  }
146
146
 
147
147
  render() {
148
- const { opdSettings, language } = this.props;
148
+ const { opdSettings, pdaLanguage, language } = this.props;
149
149
  const isHtmlOpd = this.isHtmlOpd();
150
- const constructorOpd = path(['useConstructor'], opdSettings) ? getConstructorOpd(opdSettings, language) : null;
150
+ const constructorOpd = path(['useConstructor'], opdSettings) ? getConstructorOpd(opdSettings, pdaLanguage, language) : null;
151
151
 
152
152
  return <FormContext.Consumer>{ ({ htmlAttrs }) => (
153
153
  <Fragment>