@formio/js 5.1.0-dev.6079.1fdf7d9 → 5.1.0-dev.6082.51d4e33

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.
@@ -96,6 +96,9 @@ export default class FormComponent extends Component {
96
96
  }
97
97
  return this.createSubForm();
98
98
  }
99
+ shouldConditionallyClearOnPristine() {
100
+ return !this.hasSetValue && super.shouldConditionallyClearOnPristine();
101
+ }
99
102
  get dataReady() {
100
103
  return this.subForm?.dataReady || this.subFormReady || Promise.resolve();
101
104
  }
@@ -286,11 +289,13 @@ export default class FormComponent extends Component {
286
289
  }
287
290
  this.subForm.attach(element);
288
291
  this.valueChanged = this.hasSetValue;
289
- if (!this.valueChanged && this.dataValue.state !== 'submitted') {
290
- this.setDefaultValue();
291
- }
292
- else {
293
- this.restoreValue();
292
+ if (!this.shouldConditionallyClear()) {
293
+ if (!this.valueChanged && this.dataValue.state !== 'submitted') {
294
+ this.setDefaultValue();
295
+ }
296
+ else {
297
+ this.restoreValue();
298
+ }
294
299
  }
295
300
  }
296
301
  if (!this.builderMode && this.component.modalEdit) {
@@ -405,7 +410,7 @@ export default class FormComponent extends Component {
405
410
  _.assign(componentsMap, formComponentsMap);
406
411
  this.component.components = this.subForm.components.map((comp) => comp.component);
407
412
  this.subForm.on('change', () => {
408
- if (this.subForm) {
413
+ if (this.subForm && !this.shouldConditionallyClear()) {
409
414
  this.dataValue = this.subForm.getValue();
410
415
  this.triggerChange({
411
416
  noEmit: true
@@ -668,20 +673,7 @@ export default class FormComponent extends Component {
668
673
  }
669
674
  }
670
675
  isEmpty(value = this.dataValue) {
671
- return value === null || _.isEqual(value, this.emptyValue) || (this.areAllComponentsEmpty(value?.data) && !value?._id);
672
- }
673
- areAllComponentsEmpty(data) {
674
- let res = true;
675
- if (this.subForm) {
676
- this.subForm.everyComponent((comp) => {
677
- const componentValue = _.get(data, comp.key);
678
- res &= comp.isEmpty(componentValue);
679
- });
680
- }
681
- else {
682
- res = false;
683
- }
684
- return res;
676
+ return value === null || _.isEqual(value, this.emptyValue);
685
677
  }
686
678
  getValue() {
687
679
  if (this.subForm) {
@@ -86,8 +86,8 @@ export default class TextFieldComponent extends Input {
86
86
  locale: this.component.widget.locale || this.options.language,
87
87
  saveAs: 'text'
88
88
  };
89
- // update originalComponent to include widget settings after component initialization
90
- // originalComponent is used to restore the component (and widget) after evaluating field logic
89
+ // update originalComponent to include widget settings after component initialization
90
+ // originalComponent is used to restore the component (and widget) after evaluating field logic
91
91
  this.originalComponent = FormioUtils.fastCloneDeep(this.component);
92
92
  }
93
93
  }
@@ -4,8 +4,6 @@ declare const _default: {
4
4
  invalidRowError: string;
5
5
  invalidOption: string;
6
6
  invalidDay: string;
7
- alertMessageWithLabel: string;
8
- alertMessage: string;
9
7
  complete: string;
10
8
  error: string;
11
9
  errorListHotkey: string;
@@ -6,8 +6,6 @@ export default {
6
6
  invalidRowError: 'Invalid row. Please correct it or delete.',
7
7
  invalidOption: '{{field}} is an invalid value.',
8
8
  invalidDay: '{{field}} is not a valid day.',
9
- alertMessageWithLabel: '{{label}}: {{message}}',
10
- alertMessage: '{{message}}',
11
9
  complete: 'Submission Complete',
12
10
  error: 'Please fix the following errors before submitting.',
13
11
  errorListHotkey: 'Press Ctrl + Alt + X to go back to the error list.',
@@ -490,6 +490,15 @@ export function getFocusableElements(element: HTMLElement): NodeList<HTMLElement
490
490
  * @returns {Array<string>|null} - The saved types for the component
491
491
  */
492
492
  export function getComponentSavedTypes(fullSchema: import('@formio/core').Component): Array<string> | null;
493
+ /**
494
+ * Checks if a string has timezone information encoded in it
495
+ * Example: 2024-01-01T00:00:00Z -> true
496
+ * Example: 2024-01-01T00:00:00+03:00 -> true
497
+ * Example: 2011-05-03T00:00:00 -> false
498
+ * @param {string} value the string value to check
499
+ * @returns {boolean} if value has encoded timezone
500
+ */
501
+ export function hasEncodedTimezone(value: string): boolean;
493
502
  export * from "./formUtils";
494
503
  /**
495
504
  * Map values through unfold and return first non-nil value.
@@ -1554,3 +1554,17 @@ export const interpolateErrors = (component, errors, interpolateFn) => {
1554
1554
  return { ...error, message: unescapeHTML(interpolateFn(toInterpolate, context)), context: { ...context } };
1555
1555
  });
1556
1556
  };
1557
+ /**
1558
+ * Checks if a string has timezone information encoded in it
1559
+ * Example: 2024-01-01T00:00:00Z -> true
1560
+ * Example: 2024-01-01T00:00:00+03:00 -> true
1561
+ * Example: 2011-05-03T00:00:00 -> false
1562
+ * @param {string} value the string value to check
1563
+ * @returns {boolean} if value has encoded timezone
1564
+ */
1565
+ export function hasEncodedTimezone(value) {
1566
+ if (typeof value !== 'string') {
1567
+ return false;
1568
+ }
1569
+ return (value.substring(value.length - 1) === 'z' || value.substring(value.length - 1) === 'Z' || value.match(/[+|-][0-9]{2}:[0-9]{2}$/));
1570
+ }
@@ -1,6 +1,6 @@
1
1
  import { Formio } from '../Formio';
2
2
  import InputWidget from './InputWidget';
3
- import { convertFormatToFlatpickr, convertFormatToMask, convertFormatToMoment, formatDate, formatOffset, getBrowserInfo, getDateSetting, getLocaleDateFormatInfo, momentDate, zonesLoaded, shouldLoadZones, loadZones, } from '../utils/utils';
3
+ import { convertFormatToFlatpickr, convertFormatToMask, convertFormatToMoment, formatDate, formatOffset, getBrowserInfo, getDateSetting, getLocaleDateFormatInfo, momentDate, zonesLoaded, shouldLoadZones, loadZones, hasEncodedTimezone, } from '../utils/utils';
4
4
  import moment from 'moment';
5
5
  import _ from 'lodash';
6
6
  const DEFAULT_FORMAT = 'yyyy-MM-dd hh:mm a';
@@ -278,6 +278,11 @@ export default class CalendarWidget extends InputWidget {
278
278
  value = value ? formatDate(this.timezonesUrl, value, convertFormatToMoment(this.settings.format), this.timezone, convertFormatToMoment(this.valueMomentFormat)) : value;
279
279
  return super.setValue(value);
280
280
  }
281
+ // If the component is a textfield that does not have timezone information included in the string value then skip
282
+ // the timezone offset
283
+ if (this.component.type === 'textfield' && !hasEncodedTimezone(value)) {
284
+ this.settings.skipOffset = true;
285
+ }
281
286
  const zonesLoading = this.loadZones();
282
287
  if (value) {
283
288
  if (!saveAsText && this.settings.readOnly && !zonesLoading) {
@@ -443,7 +448,7 @@ export default class CalendarWidget extends InputWidget {
443
448
  return (date, format) => {
444
449
  // Only format this if this is the altFormat and the form is readOnly.
445
450
  if (this.settings.readOnly && (format === this.settings.altFormat)) {
446
- if (!this.settings.enableTime || this.loadZones()) {
451
+ if (!this.settings.enableTime || this.loadZones() || this.settings.skipOffset) {
447
452
  return Flatpickr.formatDate(date, format);
448
453
  }
449
454
  const currentValue = new Date(this.getValue());
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@formio/js",
3
- "version": "5.1.0-dev.6079.1fdf7d9",
3
+ "version": "5.1.0-dev.6082.51d4e33",
4
4
  "description": "JavaScript powered Forms with JSON Form Builder",
5
5
  "main": "lib/cjs/index.js",
6
6
  "exports": {