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');