@experium/findy-form 1.2.41 → 1.2.45

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.
@@ -534,7 +534,7 @@ var Fields = /*#__PURE__*/function (_Component) {
534
534
  renderField: function renderField(field) {
535
535
  return /*#__PURE__*/_react["default"].createElement("div", {
536
536
  key: field.field
537
- }, field.type === 'composite' ? /*#__PURE__*/_react["default"].createElement(_react.Fragment, null, /*#__PURE__*/_react["default"].createElement("h2", null, language ? (0, _ramda.pathOr)(field.label, ['translations', 'label', language], field) : field.label), (0, _ramda.path)(['settings', 'multiple'], field) ? /*#__PURE__*/_react["default"].createElement(_reactFinalFormArrays.FieldArray, {
537
+ }, field.type === 'composite' ? /*#__PURE__*/_react["default"].createElement(_react.Fragment, null, (0, _ramda.includes)((0, _ramda.path)(['settings', 'showLabel'], field), [true, undefined]) ? /*#__PURE__*/_react["default"].createElement("h2", null, language ? (0, _ramda.pathOr)(field.label, ['translations', 'label', language], field) : field.label) : null, (0, _ramda.path)(['settings', 'multiple'], field) ? /*#__PURE__*/_react["default"].createElement(_reactFinalFormArrays.FieldArray, {
538
538
  name: field.field,
539
539
  validate: field.required ? _validation.compositeValidator : undefined,
540
540
  initialValue: _form.fieldArrayInitialValues
@@ -178,7 +178,9 @@ var File = /*#__PURE__*/function (_Component) {
178
178
  var multiple = (0, _ramda.prop)('multiple', settings);
179
179
  var type = (0, _ramda.prop)('type', settings);
180
180
  var fd = new FormData();
181
- var validFileType = (0, _validation.checkFileType)(type, file.type, allowFileExtensions);
181
+ var fileExtenstion = (0, _ramda.last)("".concat(file.name).split('.'));
182
+ var fileType = file.type || (0, _ramda.path)([type, fileExtenstion], _allowFileExtensions.defaultAllowFileExtensions);
183
+ var validFileType = (0, _validation.checkFileType)(type, file.type, fileExtenstion, allowFileExtensions);
182
184
  fd.append('file', file);
183
185
  fd.append('name', file.name);
184
186
 
@@ -199,6 +201,9 @@ var File = /*#__PURE__*/function (_Component) {
199
201
  return response.json();
200
202
  }
201
203
  }).then(function (data) {
204
+ var name = _this.props.input.name;
205
+ var fileName = data.filename;
206
+
202
207
  if (data.statusCode === 400) {
203
208
  setInputError((0, _file.getFileErrorText)(data.message));
204
209
  return _this.setState({
@@ -214,8 +219,6 @@ var File = /*#__PURE__*/function (_Component) {
214
219
  });
215
220
  }
216
221
 
217
- var name = _this.props.input.name;
218
- var fileName = data.filename;
219
222
  var url = getFileUrl ? getFileUrl(data.id) : data.id;
220
223
 
221
224
  _this.setState({
@@ -225,7 +228,8 @@ var File = /*#__PURE__*/function (_Component) {
225
228
  var fileItem = {
226
229
  url: url,
227
230
  text: fileName,
228
- contentType: file.type,
231
+ extenstion: fileExtenstion,
232
+ contentType: fileType,
229
233
  type: type
230
234
  };
231
235
 
@@ -254,7 +258,8 @@ var File = /*#__PURE__*/function (_Component) {
254
258
  } else {
255
259
  var fileItem = {
256
260
  text: file.name,
257
- contentType: file.type,
261
+ extenstion: fileExtenstion,
262
+ contentType: fileType,
258
263
  type: type
259
264
  };
260
265
  setInputError((0, _validation.getFileTypeMessage)(type, allowFileExtensions));
@@ -386,7 +391,7 @@ var File = /*#__PURE__*/function (_Component) {
386
391
  var allowFileExtensions = _this.props.allowFileExtensions;
387
392
 
388
393
  if (allowFileExtensions) {
389
- return allowFileExtensions[type] ? (0, _ramda.join)(',', (0, _ramda.values)(allowFileExtensions[type])) : _allowFileExtensions.TYPES[type];
394
+ return allowFileExtensions[type] ? ".".concat((0, _ramda.join)(', .', (0, _ramda.keys)(allowFileExtensions[type]))) : _allowFileExtensions.TYPES[type];
390
395
  } else {
391
396
  return _allowFileExtensions.TYPES[type];
392
397
  }
@@ -205,13 +205,22 @@ var HtmlOpdForm = /*#__PURE__*/function (_Component) {
205
205
  }
206
206
  }
207
207
 
208
- var separateField = OPD_DATA_CHECKBOXES[input.getAttribute('data-separate-field') || input.getAttribute('id')];
208
+ var separateField = input.getAttribute('data-separate-field');
209
209
 
210
210
  if (separateField) {
211
211
  var value = input.type === 'checkbox' ? input.checked : input.value;
212
- values[separateField] = value;
212
+ var id = OPD_DATA_CHECKBOXES[separateField];
213
+ values[id] = value;
213
214
  form.change(separateField, value);
214
215
  }
216
+
217
+ var fixedField = OPD_DATA_CHECKBOXES[input.getAttribute('id')];
218
+
219
+ if (fixedField) {
220
+ var _value = input.type === 'checkbox' ? input.checked : input.value;
221
+
222
+ values[separateField] = _value;
223
+ }
215
224
  }, inputs);
216
225
 
217
226
  _this.props.onSubmit(getHtml(_this.form.innerHTML), values);
@@ -11,7 +11,7 @@ var defaultAllowFileExtensions = {
11
11
  html: 'text/html',
12
12
  odt: 'application/vnd.oasis.opendocument.text',
13
13
  pdf: 'application/pdf',
14
- rtf: 'application/rtf, text/rtf, .rtf',
14
+ rtf: 'application/rtf',
15
15
  txt: 'text/plain',
16
16
  xls: 'application/vnd.ms-excel',
17
17
  xlsx: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
@@ -32,6 +32,6 @@ var TYPES = {
32
32
  exports.TYPES = TYPES;
33
33
  var VALIDATION_FILE_TYPES = {
34
34
  image: 'jpeg, tiff, png',
35
- document: 'doc, docx, html, odt, pdf, rtf, xls, xlsx'
35
+ document: 'doc, docx, html, odt, pdf, rtf, txt, xls, xlsx'
36
36
  };
37
37
  exports.VALIDATION_FILE_TYPES = VALIDATION_FILE_TYPES;
@@ -29,8 +29,8 @@ var checkDate = function checkDate(value) {
29
29
  return !value || value === 'incomplete';
30
30
  };
31
31
 
32
- var checkFileType = function checkFileType(fileType, mimeType) {
33
- var allowFileExtensions = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
32
+ var checkFileType = function checkFileType(fileType, mimeType, extenstion) {
33
+ var allowFileExtensions = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
34
34
 
35
35
  switch (fileType) {
36
36
  case 'audio':
@@ -39,9 +39,12 @@ var checkFileType = function checkFileType(fileType, mimeType) {
39
39
  case 'video':
40
40
  return (0, _ramda.startsWith)('video', mimeType);
41
41
 
42
- default:
42
+ case 'image':
43
43
  var allowFileTypes = (0, _ramda.join)(',', (0, _ramda.values)(allowFileExtensions && !(0, _ramda.isEmpty)(allowFileExtensions[fileType]) ? allowFileExtensions[fileType] : _allowFileExtensions.defaultAllowFileExtensions[fileType]));
44
44
  return allowFileTypes ? (0, _ramda.contains)(mimeType, (0, _ramda.split)(',', (0, _ramda.replace)(/\s/g, '', allowFileTypes))) : true;
45
+
46
+ default:
47
+ return allowFileTypes ? allowFileExtensions[fileType] : _allowFileExtensions.defaultAllowFileExtensions[fileType];
45
48
  }
46
49
  };
47
50
 
@@ -244,12 +247,12 @@ var rules = {
244
247
  var result = true;
245
248
  value.forEach(function (value) {
246
249
  if (result) {
247
- result = checkFileType(value.type, value.contentType, allowFileExtensions);
250
+ result = checkFileType(value.type, value.contentType, value.extenstion, allowFileExtensions);
248
251
  }
249
252
  });
250
253
  return result;
251
254
  } else {
252
- return checkFileType(value.type, value.contentType, allowFileExtensions);
255
+ return checkFileType(value.type, value.contentType, value.extenstion, allowFileExtensions);
253
256
  }
254
257
  }
255
258
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@experium/findy-form",
3
- "version": "1.2.41",
3
+ "version": "1.2.45",
4
4
  "main": "./lib/index.js",
5
5
  "homepage": "https://experium.github.io/findy-form",
6
6
  "repository": "https://github.com/experium/findy-form",
@@ -356,7 +356,9 @@ class Fields extends Component {
356
356
  <div key={field.field}>
357
357
  { field.type === 'composite' ?
358
358
  <Fragment>
359
- <h2>{ language ? pathOr(field.label, ['translations', 'label', language], field) : field.label }</h2>
359
+ { includes(path(['settings', 'showLabel'], field), [true, undefined]) ? (
360
+ <h2>{ language ? pathOr(field.label, ['translations', 'label', language], field) : field.label }</h2>
361
+ ) : null}
360
362
  { path(['settings', 'multiple'], field) ?
361
363
  <FieldArray
362
364
  name={field.field}
@@ -1,5 +1,5 @@
1
1
  import React, { Component } from 'react';
2
- import { prop, append, remove, isEmpty, path, pathOr, join, values } from 'ramda';
2
+ import { prop, append, remove, isEmpty, path, pathOr, join, values, keys, last } from 'ramda';
3
3
  import Modal from 'react-responsive-modal';
4
4
  import { withTranslation } from 'react-i18next';
5
5
  import getusermedia from 'getusermedia';
@@ -12,7 +12,7 @@ import styles from '../../styles/index.module.css';
12
12
  import formStyles from '../../styles/index.module.css';
13
13
  import Spinner from './Spinner';
14
14
  import { getFileErrorText } from '../../utils/file';
15
- import { TYPES } from '../../constants/allowFileExtensions';
15
+ import { TYPES, defaultAllowFileExtensions } from '../../constants/allowFileExtensions';
16
16
  import { checkFileType, getFileTypeMessage } from '../../utils/validation';
17
17
 
18
18
  const FILE_TYPES = {
@@ -55,8 +55,9 @@ class File extends Component {
55
55
  const multiple = prop('multiple', settings);
56
56
  const type = prop('type', settings);
57
57
  const fd = new FormData();
58
-
59
- const validFileType = checkFileType(type, file.type, allowFileExtensions);
58
+ const fileExtenstion = last(`${file.name}`.split('.'));
59
+ const fileType = file.type || path([type, fileExtenstion], defaultAllowFileExtensions);
60
+ const validFileType = checkFileType(type, file.type, fileExtenstion, allowFileExtensions);
60
61
 
61
62
  fd.append('file', file);
62
63
  fd.append('name', file.name);
@@ -77,6 +78,9 @@ class File extends Component {
77
78
  }
78
79
  })
79
80
  .then(data => {
81
+ const { input: { name } } = this.props;
82
+ const fileName = data.filename;
83
+
80
84
  if (data.statusCode === 400) {
81
85
  setInputError(getFileErrorText(data.message));
82
86
  return this.setState({ error: data.message || true, loading: false });
@@ -86,15 +90,14 @@ class File extends Component {
86
90
  return this.setState({ error: true, loading: false });
87
91
  }
88
92
 
89
- const { input: { name } } = this.props;
90
- const fileName = data.filename;
91
93
  const url = getFileUrl ? getFileUrl(data.id) : data.id;
92
94
  this.setState({ loading: false });
93
95
 
94
96
  const fileItem = {
95
97
  url,
96
98
  text: fileName,
97
- contentType: file.type,
99
+ extenstion: fileExtenstion,
100
+ contentType: fileType,
98
101
  type,
99
102
  };
100
103
 
@@ -118,7 +121,8 @@ class File extends Component {
118
121
  } else {
119
122
  const fileItem = {
120
123
  text: file.name,
121
- contentType: file.type,
124
+ extenstion: fileExtenstion,
125
+ contentType: fileType,
122
126
  type,
123
127
  };
124
128
 
@@ -250,7 +254,7 @@ class File extends Component {
250
254
 
251
255
  if (allowFileExtensions) {
252
256
  return allowFileExtensions[type] ? (
253
- join(',', values(allowFileExtensions[type]))
257
+ `.${join(', .', keys(allowFileExtensions[type]))}`
254
258
  ) : TYPES[type];
255
259
  } else {
256
260
  return TYPES[type];
@@ -243,13 +243,20 @@ class HtmlOpdForm extends Component {
243
243
  }
244
244
  }
245
245
 
246
- const separateField = OPD_DATA_CHECKBOXES[input.getAttribute('data-separate-field') || input.getAttribute('id')];
246
+ const separateField = input.getAttribute('data-separate-field');
247
247
 
248
248
  if (separateField) {
249
249
  const value = input.type === 'checkbox' ? input.checked : input.value;
250
- values[separateField] = value;
250
+ const id = OPD_DATA_CHECKBOXES[separateField];
251
+ values[id] = value;
251
252
  form.change(separateField, value);
252
253
  }
254
+
255
+ const fixedField = OPD_DATA_CHECKBOXES[input.getAttribute('id')];
256
+ if (fixedField) {
257
+ const value = input.type === 'checkbox' ? input.checked : input.value;
258
+ values[separateField] = value;
259
+ }
253
260
  }, inputs);
254
261
 
255
262
  this.props.onSubmit(getHtml(this.form.innerHTML), values);
@@ -5,7 +5,7 @@ export const defaultAllowFileExtensions = {
5
5
  html: 'text/html',
6
6
  odt: 'application/vnd.oasis.opendocument.text',
7
7
  pdf: 'application/pdf',
8
- rtf: 'application/rtf, text/rtf, .rtf',
8
+ rtf: 'application/rtf',
9
9
  txt: 'text/plain',
10
10
  xls: 'application/vnd.ms-excel',
11
11
  xlsx: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
@@ -26,5 +26,5 @@ export const TYPES = {
26
26
 
27
27
  export const VALIDATION_FILE_TYPES = {
28
28
  image: 'jpeg, tiff, png',
29
- document: 'doc, docx, html, odt, pdf, rtf, xls, xlsx',
29
+ document: 'doc, docx, html, odt, pdf, rtf, txt, xls, xlsx',
30
30
  };
@@ -11,18 +11,20 @@ import { defaultAllowFileExtensions, VALIDATION_FILE_TYPES } from '../constants/
11
11
 
12
12
  const checkDate = value => !value || value === 'incomplete';
13
13
 
14
- export const checkFileType = (fileType, mimeType, allowFileExtensions = {}) => {
14
+ export const checkFileType = (fileType, mimeType, extenstion, allowFileExtensions = {}) => {
15
15
  switch (fileType) {
16
16
  case 'audio':
17
17
  return startsWith('audio', mimeType);
18
18
  case 'video':
19
19
  return startsWith('video', mimeType);
20
- default:
20
+ case 'image':
21
21
  const allowFileTypes = join(',', values(
22
22
  allowFileExtensions && !isEmpty(allowFileExtensions[fileType]) ? allowFileExtensions[fileType] : defaultAllowFileExtensions[fileType]
23
23
  ));
24
24
 
25
25
  return allowFileTypes ? contains(mimeType, split(',', replace(/\s/g, '', allowFileTypes))) : true;
26
+ default:
27
+ return allowFileTypes ? allowFileExtensions[fileType] : defaultAllowFileExtensions[fileType];
26
28
  }
27
29
  };
28
30
  export const getFileTypeMessage = (type, allowFileExtensions = {}) => {
@@ -194,13 +196,13 @@ const rules = {
194
196
 
195
197
  value.forEach(value => {
196
198
  if (result) {
197
- result = checkFileType(value.type, value.contentType, allowFileExtensions);
199
+ result = checkFileType(value.type, value.contentType, value.extenstion, allowFileExtensions);
198
200
  }
199
201
  });
200
202
 
201
203
  return result;
202
204
  } else {
203
- return checkFileType(value.type, value.contentType, allowFileExtensions);
205
+ return checkFileType(value.type, value.contentType, value.extenstion, allowFileExtensions);
204
206
  }
205
207
  },
206
208
  }),