@formio/js 5.0.0-dev.5800.896e9df → 5.0.0-dev.5801.effff2f

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.
Files changed (40) hide show
  1. package/Changelog.md +4 -0
  2. package/dist/formio.form.js +5 -5
  3. package/dist/formio.form.min.js +1 -1
  4. package/dist/formio.full.js +12 -12
  5. package/dist/formio.full.min.js +1 -1
  6. package/lib/cjs/Webform.js +3 -0
  7. package/lib/cjs/components/day/Day.d.ts +5 -0
  8. package/lib/cjs/components/day/Day.js +51 -11
  9. package/lib/cjs/components/day/editForm/Day.edit.day.d.ts +17 -0
  10. package/lib/cjs/components/day/editForm/Day.edit.day.js +19 -0
  11. package/lib/cjs/components/day/editForm/Day.edit.month.d.ts +5 -0
  12. package/lib/cjs/components/day/editForm/Day.edit.month.js +19 -0
  13. package/lib/cjs/components/day/editForm/Day.edit.year.d.ts +5 -0
  14. package/lib/cjs/components/day/editForm/Day.edit.year.js +13 -0
  15. package/lib/cjs/components/radio/Radio.js +1 -1
  16. package/lib/cjs/components/select/Select.js +5 -2
  17. package/lib/cjs/components/select/editForm/Select.edit.validation.js +2 -1
  18. package/lib/cjs/components/select/fixtures/comp27.d.ts +18 -0
  19. package/lib/cjs/components/select/fixtures/comp27.js +19 -0
  20. package/lib/cjs/components/select/fixtures/index.d.ts +2 -1
  21. package/lib/cjs/components/select/fixtures/index.js +3 -1
  22. package/lib/cjs/components/selectboxes/SelectBoxes.js +1 -1
  23. package/lib/mjs/Webform.js +3 -0
  24. package/lib/mjs/components/day/Day.d.ts +5 -0
  25. package/lib/mjs/components/day/Day.js +51 -11
  26. package/lib/mjs/components/day/editForm/Day.edit.day.d.ts +17 -0
  27. package/lib/mjs/components/day/editForm/Day.edit.day.js +16 -0
  28. package/lib/mjs/components/day/editForm/Day.edit.month.d.ts +5 -0
  29. package/lib/mjs/components/day/editForm/Day.edit.month.js +16 -0
  30. package/lib/mjs/components/day/editForm/Day.edit.year.d.ts +5 -0
  31. package/lib/mjs/components/day/editForm/Day.edit.year.js +10 -0
  32. package/lib/mjs/components/radio/Radio.js +1 -1
  33. package/lib/mjs/components/select/Select.js +5 -2
  34. package/lib/mjs/components/select/editForm/Select.edit.validation.js +2 -1
  35. package/lib/mjs/components/select/fixtures/comp27.d.ts +18 -0
  36. package/lib/mjs/components/select/fixtures/comp27.js +17 -0
  37. package/lib/mjs/components/select/fixtures/index.d.ts +2 -1
  38. package/lib/mjs/components/select/fixtures/index.js +2 -1
  39. package/lib/mjs/components/selectboxes/SelectBoxes.js +1 -1
  40. package/package.json +1 -1
@@ -1098,6 +1098,9 @@ class Webform extends NestedDataComponent_1.default {
1098
1098
  if (!Array.isArray(errors)) {
1099
1099
  errors = [errors];
1100
1100
  }
1101
+ if (Array.isArray(this.errors)) {
1102
+ errors = lodash_1.default.union(errors, this.errors);
1103
+ }
1101
1104
  errors = errors.concat(this.customErrors).filter((err) => !!err);
1102
1105
  if (!errors.length) {
1103
1106
  this.setAlert(false);
@@ -97,6 +97,11 @@ export default class DayComponent extends Field {
97
97
  * @returns {null|void} - Returns null if the value is invalid, otherwise void.
98
98
  */
99
99
  setValueAt(index: number, value: any): null | void;
100
+ getDayWithHiddenFields(parts: any): {
101
+ month: any;
102
+ day: any;
103
+ year: any;
104
+ };
100
105
  getFieldValue(name: any): number;
101
106
  get parts(): {
102
107
  day: number;
@@ -344,6 +344,18 @@ class DayComponent extends Field_1.default {
344
344
  const valueParts = value.split('/');
345
345
  const [DAY, MONTH, YEAR] = this.component.dayFirst ? [0, 1, 2] : [1, 0, 2];
346
346
  const defaultValue = this.component.defaultValue ? this.component.defaultValue.split('/') : '';
347
+ let defaultDay = '';
348
+ let defaultMonth = '';
349
+ let defaultYear = '';
350
+ if (defaultValue) {
351
+ const hasHiddenFields = defaultValue.length !== 3;
352
+ defaultDay = hasHiddenFields ? this.getDayWithHiddenFields(defaultValue).day : defaultValue[DAY];
353
+ defaultMonth = hasHiddenFields ? this.getDayWithHiddenFields(defaultValue).month : defaultValue[MONTH];
354
+ defaultYear = hasHiddenFields ? this.getDayWithHiddenFields(defaultValue).year : defaultValue[YEAR];
355
+ }
356
+ if (this.options.building && defaultValue.length === 3) {
357
+ return this.component.defaultValue;
358
+ }
347
359
  const getNextPart = (shouldTake, defaultValue) => {
348
360
  // Only push the part if it's not an empty string
349
361
  const part = shouldTake ? valueParts.shift() : defaultValue;
@@ -352,13 +364,13 @@ class DayComponent extends Field_1.default {
352
364
  }
353
365
  };
354
366
  if (this.dayFirst) {
355
- getNextPart(this.showDay, defaultValue ? defaultValue[DAY] : '');
367
+ getNextPart(this.showDay, defaultDay);
356
368
  }
357
- getNextPart(this.showMonth, defaultValue ? defaultValue[MONTH] : '');
369
+ getNextPart(this.showMonth, defaultMonth);
358
370
  if (!this.dayFirst) {
359
- getNextPart(this.showDay, defaultValue ? defaultValue[DAY] : '');
371
+ getNextPart(this.showDay, defaultDay);
360
372
  }
361
- getNextPart(this.showYear, defaultValue ? defaultValue[YEAR] : '');
373
+ getNextPart(this.showYear, defaultYear);
362
374
  return dateParts.join('/');
363
375
  }
364
376
  /**
@@ -373,16 +385,23 @@ class DayComponent extends Field_1.default {
373
385
  if (value === 'Invalid date') {
374
386
  return null;
375
387
  }
388
+ let day, month, year;
376
389
  const parts = value.split('/');
377
- let day;
378
- if (this.component.dayFirst) {
379
- day = parts.shift();
390
+ if (parts.length !== 3) {
391
+ day = this.getDayWithHiddenFields(parts).day;
392
+ month = this.getDayWithHiddenFields(parts).month;
393
+ year = this.getDayWithHiddenFields(parts).year;
380
394
  }
381
- const month = parts.shift();
382
- if (!this.component.dayFirst) {
383
- day = parts.shift();
395
+ else {
396
+ if (this.component.dayFirst) {
397
+ day = parts.shift();
398
+ }
399
+ month = parts.shift();
400
+ if (!this.component.dayFirst) {
401
+ day = parts.shift();
402
+ }
403
+ year = parts.shift();
384
404
  }
385
- const year = parts.shift();
386
405
  if (this.refs.day && this.showDay) {
387
406
  this.refs.day.value = day === '00' ? '' : parseInt(day, 10);
388
407
  }
@@ -393,6 +412,27 @@ class DayComponent extends Field_1.default {
393
412
  this.refs.year.value = year === '0000' ? '' : parseInt(year, 10);
394
413
  }
395
414
  }
415
+ getDayWithHiddenFields(parts) {
416
+ let [DAY, MONTH, YEAR] = this.component.dayFirst ? [0, 1, 2] : [1, 0, 2];
417
+ if (!this.showDay) {
418
+ MONTH = MONTH === 0 ? 0 : MONTH - 1;
419
+ YEAR = YEAR - 1;
420
+ DAY = null;
421
+ }
422
+ if (!this.showMonth) {
423
+ DAY = DAY === 0 ? 0 : DAY - 1;
424
+ YEAR = YEAR - 1;
425
+ MONTH = null;
426
+ }
427
+ if (!this.showYear) {
428
+ YEAR = null;
429
+ }
430
+ return {
431
+ month: lodash_1.default.isNull(MONTH) ? '' : parts[MONTH],
432
+ day: lodash_1.default.isNull(DAY) ? '' : parts[DAY],
433
+ year: lodash_1.default.isNull(YEAR) ? '' : parts[YEAR],
434
+ };
435
+ }
396
436
  getFieldValue(name) {
397
437
  const parts = this.dataValue ? this.dataValue.split('/') : [];
398
438
  let val = 0;
@@ -14,6 +14,7 @@ declare const _default: ({
14
14
  input?: undefined;
15
15
  placeholder?: undefined;
16
16
  tooltip?: undefined;
17
+ onChange?: undefined;
17
18
  } | {
18
19
  weight: number;
19
20
  type: string;
@@ -25,16 +26,32 @@ declare const _default: ({
25
26
  wieght?: undefined;
26
27
  datasrc?: undefined;
27
28
  data?: undefined;
29
+ onChange?: undefined;
28
30
  } | {
29
31
  weight: number;
30
32
  type: string;
31
33
  label: string;
32
34
  tooltip: string;
33
35
  key: string;
36
+ onChange: ({ data }: {
37
+ data: any;
38
+ }) => void;
34
39
  input: boolean;
35
40
  wieght?: undefined;
36
41
  datasrc?: undefined;
37
42
  data?: undefined;
38
43
  placeholder?: undefined;
44
+ } | {
45
+ weight: number;
46
+ type: string;
47
+ label: string;
48
+ tooltip: string;
49
+ key: string;
50
+ input: boolean;
51
+ wieght?: undefined;
52
+ datasrc?: undefined;
53
+ data?: undefined;
54
+ placeholder?: undefined;
55
+ onChange?: undefined;
39
56
  })[];
40
57
  export default _default;
@@ -1,5 +1,9 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
+ const lodash_1 = __importDefault(require("lodash"));
3
7
  exports.default = [
4
8
  {
5
9
  wieght: 200,
@@ -35,6 +39,21 @@ exports.default = [
35
39
  label: 'Hidden',
36
40
  tooltip: 'Hide the Day part of the component.',
37
41
  key: 'fields.day.hide',
42
+ onChange: ({ data }) => {
43
+ if (data.defaultValue) {
44
+ const defaultValueParts = data.defaultValue.split('/');
45
+ if (!data.fields.day.hide && defaultValueParts.length !== 3) {
46
+ const newDefaultValue = ['00'];
47
+ if (!data.fields.month.hide) {
48
+ data.dayFirst ? newDefaultValue.push(defaultValueParts[0]) : newDefaultValue.unshift(defaultValueParts[0]);
49
+ }
50
+ if (!data.fields.year.hide) {
51
+ newDefaultValue.push(defaultValueParts[1]);
52
+ }
53
+ lodash_1.default.set(data, 'defaultValue', newDefaultValue.join('/'));
54
+ }
55
+ }
56
+ },
38
57
  input: true
39
58
  },
40
59
  {
@@ -14,6 +14,7 @@ declare const _default: ({
14
14
  input?: undefined;
15
15
  placeholder?: undefined;
16
16
  tooltip?: undefined;
17
+ onChange?: undefined;
17
18
  } | {
18
19
  weight: number;
19
20
  type: string;
@@ -25,12 +26,16 @@ declare const _default: ({
25
26
  wieght?: undefined;
26
27
  datasrc?: undefined;
27
28
  data?: undefined;
29
+ onChange?: undefined;
28
30
  } | {
29
31
  weight: number;
30
32
  type: string;
31
33
  label: string;
32
34
  tooltip: string;
33
35
  key: string;
36
+ onChange: ({ data }: {
37
+ data: any;
38
+ }) => void;
34
39
  input: boolean;
35
40
  wieght?: undefined;
36
41
  datasrc?: undefined;
@@ -1,5 +1,9 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
+ const lodash_1 = __importDefault(require("lodash"));
3
7
  exports.default = [
4
8
  {
5
9
  wieght: 200,
@@ -35,6 +39,21 @@ exports.default = [
35
39
  label: 'Hidden',
36
40
  tooltip: 'Hide the Month part of the component.',
37
41
  key: 'fields.month.hide',
42
+ onChange: ({ data }) => {
43
+ if (data.defaultValue) {
44
+ const defaultValueParts = data.defaultValue.split('/');
45
+ if (!data.fields.month.hide && defaultValueParts.length !== 3) {
46
+ const newDefaultValue = ['00'];
47
+ if (!data.fields.day.hide) {
48
+ data.dayFirst ? newDefaultValue.unshift(defaultValueParts[0]) : newDefaultValue.push(defaultValueParts[0]);
49
+ }
50
+ if (!data.fields.year.hide) {
51
+ newDefaultValue.push(defaultValueParts[1]);
52
+ }
53
+ lodash_1.default.set(data, 'defaultValue', newDefaultValue.join('/'));
54
+ }
55
+ }
56
+ },
38
57
  input: true
39
58
  },
40
59
  ];
@@ -14,6 +14,7 @@ declare const _default: ({
14
14
  input?: undefined;
15
15
  placeholder?: undefined;
16
16
  tooltip?: undefined;
17
+ onChange?: undefined;
17
18
  } | {
18
19
  weight: number;
19
20
  type: string;
@@ -25,12 +26,16 @@ declare const _default: ({
25
26
  wieght?: undefined;
26
27
  datasrc?: undefined;
27
28
  data?: undefined;
29
+ onChange?: undefined;
28
30
  } | {
29
31
  weight: number;
30
32
  type: string;
31
33
  label: string;
32
34
  tooltip: string;
33
35
  key: string;
36
+ onChange: ({ data }: {
37
+ data: any;
38
+ }) => void;
34
39
  input: boolean;
35
40
  wieght?: undefined;
36
41
  datasrc?: undefined;
@@ -1,5 +1,9 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
+ const lodash_1 = __importDefault(require("lodash"));
3
7
  exports.default = [
4
8
  {
5
9
  wieght: 200,
@@ -53,6 +57,15 @@ exports.default = [
53
57
  label: 'Hidden',
54
58
  tooltip: 'Hide the Year part of the component.',
55
59
  key: 'fields.year.hide',
60
+ onChange: ({ data }) => {
61
+ if (data.defaultValue) {
62
+ const defaultValueParts = data.defaultValue.split('/');
63
+ if (!data.fields.month.hide && defaultValueParts.length !== 3) {
64
+ defaultValueParts.push('0000');
65
+ lodash_1.default.set(data, 'defaultValue', defaultValueParts.join('/'));
66
+ }
67
+ }
68
+ },
56
69
  input: true
57
70
  },
58
71
  ];
@@ -212,7 +212,7 @@ class RadioComponent extends ListComponent_1.default {
212
212
  if (!(0, utils_1.boolValue)(setting) || !value) {
213
213
  return true;
214
214
  }
215
- const values = this.component.values;
215
+ const values = this.component.dataSrc === 'values' ? this.component.values : this.loadedOptions;
216
216
  if (values) {
217
217
  return values.findIndex(({ value: optionValue }) => this.normalizeValue(optionValue) === value) !== -1;
218
218
  }
@@ -1429,6 +1429,9 @@ class SelectComponent extends ListComponent_1.default {
1429
1429
  case 'custom':
1430
1430
  rawItems = this.getCustomItems();
1431
1431
  break;
1432
+ case 'url':
1433
+ rawItems = this.selectItems;
1434
+ break;
1432
1435
  }
1433
1436
  if (typeof rawItems === 'string') {
1434
1437
  try {
@@ -1487,7 +1490,7 @@ class SelectComponent extends ListComponent_1.default {
1487
1490
  if (Array.isArray(data)) {
1488
1491
  data.forEach((item) => item[valueProperty] = item[valueProperty].toString());
1489
1492
  }
1490
- else {
1493
+ else if (lodash_1.default.isObject(data)) {
1491
1494
  data[valueProperty] = data[valueProperty].toString();
1492
1495
  }
1493
1496
  return data;
@@ -1522,7 +1525,7 @@ class SelectComponent extends ListComponent_1.default {
1522
1525
  };
1523
1526
  value = (this.component.multiple && Array.isArray(value))
1524
1527
  ? lodash_1.default.filter(items, (item) => value.includes(item.value))
1525
- : valueProperty
1528
+ : (valueProperty && items)
1526
1529
  ? (_a = getFromValues()) !== null && _a !== void 0 ? _a : { value, label: value }
1527
1530
  : value;
1528
1531
  }
@@ -26,7 +26,8 @@ exports.default = [
26
26
  [
27
27
  'values',
28
28
  'json',
29
- 'custom'
29
+ 'custom',
30
+ 'url'
30
31
  ],
31
32
  ],
32
33
  },
@@ -0,0 +1,18 @@
1
+ declare namespace _default {
2
+ let type: string;
3
+ let label: string;
4
+ let widget: string;
5
+ let tableView: boolean;
6
+ let dataSrc: string;
7
+ namespace data {
8
+ let custom: string;
9
+ }
10
+ let dataType: string;
11
+ let idPath: string;
12
+ let valueProperty: string;
13
+ let template: string;
14
+ let validateWhenHidden: boolean;
15
+ let key: string;
16
+ let input: boolean;
17
+ }
18
+ export default _default;
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.default = {
4
+ type: 'select',
5
+ label: 'Select',
6
+ widget: 'choicesjs',
7
+ tableView: true,
8
+ dataSrc: 'custom',
9
+ data: {
10
+ custom: 'values = data.dataSource;'
11
+ },
12
+ dataType: 'string',
13
+ idPath: 'name',
14
+ valueProperty: 'name',
15
+ template: '<span>{{ item.name }}</span>',
16
+ validateWhenHidden: false,
17
+ key: 'select',
18
+ input: true
19
+ };
@@ -23,5 +23,6 @@ import comp23 from './comp23';
23
23
  import comp24 from './comp24';
24
24
  import comp25 from './comp25';
25
25
  import comp26 from './comp26';
26
- export { comp1, comp2, comp4, comp5, comp6, comp7, comp8, comp9, comp10, comp11, comp12, comp13, comp14, comp15, comp16, comp17, comp18, comp19, comp20, comp21, comp22, comp23, comp24, comp25, comp26 };
26
+ import comp27 from './comp27';
27
+ export { comp1, comp2, comp4, comp5, comp6, comp7, comp8, comp9, comp10, comp11, comp12, comp13, comp14, comp15, comp16, comp17, comp18, comp19, comp20, comp21, comp22, comp23, comp24, comp25, comp26, comp27 };
27
28
  export { multiSelect, multiSelectOptions } from "./comp3";
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.comp26 = exports.comp25 = exports.comp24 = exports.comp23 = exports.comp22 = exports.comp21 = exports.comp20 = exports.comp19 = exports.comp18 = exports.comp17 = exports.comp16 = exports.comp15 = exports.comp14 = exports.comp13 = exports.comp12 = exports.comp11 = exports.comp10 = exports.comp9 = exports.comp8 = exports.comp7 = exports.comp6 = exports.comp5 = exports.comp4 = exports.comp2 = exports.comp1 = exports.multiSelectOptions = exports.multiSelect = void 0;
6
+ exports.comp27 = exports.comp26 = exports.comp25 = exports.comp24 = exports.comp23 = exports.comp22 = exports.comp21 = exports.comp20 = exports.comp19 = exports.comp18 = exports.comp17 = exports.comp16 = exports.comp15 = exports.comp14 = exports.comp13 = exports.comp12 = exports.comp11 = exports.comp10 = exports.comp9 = exports.comp8 = exports.comp7 = exports.comp6 = exports.comp5 = exports.comp4 = exports.comp2 = exports.comp1 = exports.multiSelectOptions = exports.multiSelect = void 0;
7
7
  const comp1_1 = __importDefault(require("./comp1"));
8
8
  exports.comp1 = comp1_1.default;
9
9
  const comp2_1 = __importDefault(require("./comp2"));
@@ -57,3 +57,5 @@ const comp25_1 = __importDefault(require("./comp25"));
57
57
  exports.comp25 = comp25_1.default;
58
58
  const comp26_1 = __importDefault(require("./comp26"));
59
59
  exports.comp26 = comp26_1.default;
60
+ const comp27_1 = __importDefault(require("./comp27"));
61
+ exports.comp27 = comp27_1.default;
@@ -254,7 +254,7 @@ class SelectBoxesComponent extends Radio_1.default {
254
254
  if (!(0, utils_1.boolValue)(setting) || !value) {
255
255
  return true;
256
256
  }
257
- const values = this.component.values;
257
+ const values = this.component.dataSrc === 'values' ? this.component.values : this.loadedOptions;
258
258
  const availableValueKeys = (values || []).map(({ value: optionValue }) => optionValue);
259
259
  const valueKeys = Object.keys(value);
260
260
  return valueKeys.every((key) => availableValueKeys.includes(key));
@@ -1102,6 +1102,9 @@ export default class Webform extends NestedDataComponent {
1102
1102
  if (!Array.isArray(errors)) {
1103
1103
  errors = [errors];
1104
1104
  }
1105
+ if (Array.isArray(this.errors)) {
1106
+ errors = _.union(errors, this.errors);
1107
+ }
1105
1108
  errors = errors.concat(this.customErrors).filter((err) => !!err);
1106
1109
  if (!errors.length) {
1107
1110
  this.setAlert(false);
@@ -97,6 +97,11 @@ export default class DayComponent extends Field {
97
97
  * @returns {null|void} - Returns null if the value is invalid, otherwise void.
98
98
  */
99
99
  setValueAt(index: number, value: any): null | void;
100
+ getDayWithHiddenFields(parts: any): {
101
+ month: any;
102
+ day: any;
103
+ year: any;
104
+ };
100
105
  getFieldValue(name: any): number;
101
106
  get parts(): {
102
107
  day: number;
@@ -342,6 +342,18 @@ export default class DayComponent extends Field {
342
342
  const valueParts = value.split('/');
343
343
  const [DAY, MONTH, YEAR] = this.component.dayFirst ? [0, 1, 2] : [1, 0, 2];
344
344
  const defaultValue = this.component.defaultValue ? this.component.defaultValue.split('/') : '';
345
+ let defaultDay = '';
346
+ let defaultMonth = '';
347
+ let defaultYear = '';
348
+ if (defaultValue) {
349
+ const hasHiddenFields = defaultValue.length !== 3;
350
+ defaultDay = hasHiddenFields ? this.getDayWithHiddenFields(defaultValue).day : defaultValue[DAY];
351
+ defaultMonth = hasHiddenFields ? this.getDayWithHiddenFields(defaultValue).month : defaultValue[MONTH];
352
+ defaultYear = hasHiddenFields ? this.getDayWithHiddenFields(defaultValue).year : defaultValue[YEAR];
353
+ }
354
+ if (this.options.building && defaultValue.length === 3) {
355
+ return this.component.defaultValue;
356
+ }
345
357
  const getNextPart = (shouldTake, defaultValue) => {
346
358
  // Only push the part if it's not an empty string
347
359
  const part = shouldTake ? valueParts.shift() : defaultValue;
@@ -350,13 +362,13 @@ export default class DayComponent extends Field {
350
362
  }
351
363
  };
352
364
  if (this.dayFirst) {
353
- getNextPart(this.showDay, defaultValue ? defaultValue[DAY] : '');
365
+ getNextPart(this.showDay, defaultDay);
354
366
  }
355
- getNextPart(this.showMonth, defaultValue ? defaultValue[MONTH] : '');
367
+ getNextPart(this.showMonth, defaultMonth);
356
368
  if (!this.dayFirst) {
357
- getNextPart(this.showDay, defaultValue ? defaultValue[DAY] : '');
369
+ getNextPart(this.showDay, defaultDay);
358
370
  }
359
- getNextPart(this.showYear, defaultValue ? defaultValue[YEAR] : '');
371
+ getNextPart(this.showYear, defaultYear);
360
372
  return dateParts.join('/');
361
373
  }
362
374
  /**
@@ -371,16 +383,23 @@ export default class DayComponent extends Field {
371
383
  if (value === 'Invalid date') {
372
384
  return null;
373
385
  }
386
+ let day, month, year;
374
387
  const parts = value.split('/');
375
- let day;
376
- if (this.component.dayFirst) {
377
- day = parts.shift();
388
+ if (parts.length !== 3) {
389
+ day = this.getDayWithHiddenFields(parts).day;
390
+ month = this.getDayWithHiddenFields(parts).month;
391
+ year = this.getDayWithHiddenFields(parts).year;
378
392
  }
379
- const month = parts.shift();
380
- if (!this.component.dayFirst) {
381
- day = parts.shift();
393
+ else {
394
+ if (this.component.dayFirst) {
395
+ day = parts.shift();
396
+ }
397
+ month = parts.shift();
398
+ if (!this.component.dayFirst) {
399
+ day = parts.shift();
400
+ }
401
+ year = parts.shift();
382
402
  }
383
- const year = parts.shift();
384
403
  if (this.refs.day && this.showDay) {
385
404
  this.refs.day.value = day === '00' ? '' : parseInt(day, 10);
386
405
  }
@@ -391,6 +410,27 @@ export default class DayComponent extends Field {
391
410
  this.refs.year.value = year === '0000' ? '' : parseInt(year, 10);
392
411
  }
393
412
  }
413
+ getDayWithHiddenFields(parts) {
414
+ let [DAY, MONTH, YEAR] = this.component.dayFirst ? [0, 1, 2] : [1, 0, 2];
415
+ if (!this.showDay) {
416
+ MONTH = MONTH === 0 ? 0 : MONTH - 1;
417
+ YEAR = YEAR - 1;
418
+ DAY = null;
419
+ }
420
+ if (!this.showMonth) {
421
+ DAY = DAY === 0 ? 0 : DAY - 1;
422
+ YEAR = YEAR - 1;
423
+ MONTH = null;
424
+ }
425
+ if (!this.showYear) {
426
+ YEAR = null;
427
+ }
428
+ return {
429
+ month: _.isNull(MONTH) ? '' : parts[MONTH],
430
+ day: _.isNull(DAY) ? '' : parts[DAY],
431
+ year: _.isNull(YEAR) ? '' : parts[YEAR],
432
+ };
433
+ }
394
434
  getFieldValue(name) {
395
435
  const parts = this.dataValue ? this.dataValue.split('/') : [];
396
436
  let val = 0;
@@ -14,6 +14,7 @@ declare const _default: ({
14
14
  input?: undefined;
15
15
  placeholder?: undefined;
16
16
  tooltip?: undefined;
17
+ onChange?: undefined;
17
18
  } | {
18
19
  weight: number;
19
20
  type: string;
@@ -25,16 +26,32 @@ declare const _default: ({
25
26
  wieght?: undefined;
26
27
  datasrc?: undefined;
27
28
  data?: undefined;
29
+ onChange?: undefined;
28
30
  } | {
29
31
  weight: number;
30
32
  type: string;
31
33
  label: string;
32
34
  tooltip: string;
33
35
  key: string;
36
+ onChange: ({ data }: {
37
+ data: any;
38
+ }) => void;
34
39
  input: boolean;
35
40
  wieght?: undefined;
36
41
  datasrc?: undefined;
37
42
  data?: undefined;
38
43
  placeholder?: undefined;
44
+ } | {
45
+ weight: number;
46
+ type: string;
47
+ label: string;
48
+ tooltip: string;
49
+ key: string;
50
+ input: boolean;
51
+ wieght?: undefined;
52
+ datasrc?: undefined;
53
+ data?: undefined;
54
+ placeholder?: undefined;
55
+ onChange?: undefined;
39
56
  })[];
40
57
  export default _default;
@@ -1,3 +1,4 @@
1
+ import _ from 'lodash';
1
2
  export default [
2
3
  {
3
4
  wieght: 200,
@@ -33,6 +34,21 @@ export default [
33
34
  label: 'Hidden',
34
35
  tooltip: 'Hide the Day part of the component.',
35
36
  key: 'fields.day.hide',
37
+ onChange: ({ data }) => {
38
+ if (data.defaultValue) {
39
+ const defaultValueParts = data.defaultValue.split('/');
40
+ if (!data.fields.day.hide && defaultValueParts.length !== 3) {
41
+ const newDefaultValue = ['00'];
42
+ if (!data.fields.month.hide) {
43
+ data.dayFirst ? newDefaultValue.push(defaultValueParts[0]) : newDefaultValue.unshift(defaultValueParts[0]);
44
+ }
45
+ if (!data.fields.year.hide) {
46
+ newDefaultValue.push(defaultValueParts[1]);
47
+ }
48
+ _.set(data, 'defaultValue', newDefaultValue.join('/'));
49
+ }
50
+ }
51
+ },
36
52
  input: true
37
53
  },
38
54
  {
@@ -14,6 +14,7 @@ declare const _default: ({
14
14
  input?: undefined;
15
15
  placeholder?: undefined;
16
16
  tooltip?: undefined;
17
+ onChange?: undefined;
17
18
  } | {
18
19
  weight: number;
19
20
  type: string;
@@ -25,12 +26,16 @@ declare const _default: ({
25
26
  wieght?: undefined;
26
27
  datasrc?: undefined;
27
28
  data?: undefined;
29
+ onChange?: undefined;
28
30
  } | {
29
31
  weight: number;
30
32
  type: string;
31
33
  label: string;
32
34
  tooltip: string;
33
35
  key: string;
36
+ onChange: ({ data }: {
37
+ data: any;
38
+ }) => void;
34
39
  input: boolean;
35
40
  wieght?: undefined;
36
41
  datasrc?: undefined;
@@ -1,3 +1,4 @@
1
+ import _ from 'lodash';
1
2
  export default [
2
3
  {
3
4
  wieght: 200,
@@ -33,6 +34,21 @@ export default [
33
34
  label: 'Hidden',
34
35
  tooltip: 'Hide the Month part of the component.',
35
36
  key: 'fields.month.hide',
37
+ onChange: ({ data }) => {
38
+ if (data.defaultValue) {
39
+ const defaultValueParts = data.defaultValue.split('/');
40
+ if (!data.fields.month.hide && defaultValueParts.length !== 3) {
41
+ const newDefaultValue = ['00'];
42
+ if (!data.fields.day.hide) {
43
+ data.dayFirst ? newDefaultValue.unshift(defaultValueParts[0]) : newDefaultValue.push(defaultValueParts[0]);
44
+ }
45
+ if (!data.fields.year.hide) {
46
+ newDefaultValue.push(defaultValueParts[1]);
47
+ }
48
+ _.set(data, 'defaultValue', newDefaultValue.join('/'));
49
+ }
50
+ }
51
+ },
36
52
  input: true
37
53
  },
38
54
  ];