From 6f6d5bb728d42a3e29a574b874a4899c0ce2ab96 Mon Sep 17 00:00:00 2001 From: Blake Krammes <49688912+blakekrammes@users.noreply.github.com> Date: Tue, 19 Nov 2024 04:10:35 -0600 Subject: [PATCH] FIO-9217 Fix: allow moment.js datetime custom default values in calendar widget-text field components (#5907) - For some reason the default mask was being set to an empty array for this scenario --- .../_classes/component/Component.js | 2 +- test/unit/TextField.unit.js | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/components/_classes/component/Component.js b/src/components/_classes/component/Component.js index c25b280a2c..1f5f374733 100644 --- a/src/components/_classes/component/Component.js +++ b/src/components/_classes/component/Component.js @@ -2884,7 +2884,7 @@ export default class Component extends Element { return value; }; - if (this.defaultMask) { + if (Array.isArray(this.defaultMask) ? this.defaultMask.length > 0 : this.defaultMask) { if (Array.isArray(defaultValue)) { defaultValue = defaultValue.map(checkMask); } diff --git a/test/unit/TextField.unit.js b/test/unit/TextField.unit.js index 5016e3b0b2..f6f3bdb609 100644 --- a/test/unit/TextField.unit.js +++ b/test/unit/TextField.unit.js @@ -15,6 +15,8 @@ import { comp7, } from './fixtures/textfield'; +import { comp10 as formWithCalendarTextField } from './fixtures/datetime'; + describe('TextField Component', () => { it('Should create a new TextField', () => { const textField = new TextFieldComponent({ @@ -1359,6 +1361,23 @@ describe('TextField Component', () => { }, 300); }).catch(done); }); + // see https://formio.atlassian.net/browse/FIO-9217 + it('Should allow the populating of a calendar widget–text field component with a custom default value that is a moment datetime', (done) => { + const form = _.cloneDeep(formWithCalendarTextField); + const textFieldComponent = form.components[1]; + textFieldComponent.customDefaultValue = "value=moment('2024-11-13 15:00:00')"; + + const element = document.createElement('div'); + + Formio.createForm(element, form).then(renderedForm => { + const renderedTextFieldComponent = renderedForm.getComponent('textField'); + setTimeout(() => { + const input = renderedTextFieldComponent.element.querySelector('.input'); + assert.equal(input.value, '2024-11-13 03:00 PM'); + done(); + }, 200); + }).catch(done); + }); it('Test Display mask', (done) => { const element = document.createElement('div');