Skip to content

Commit

Permalink
FIO-9217 Fix: allow moment.js datetime custom default values in calen…
Browse files Browse the repository at this point in the history
…dar widget-text field components (#5907)

- For some reason the default mask was being set to an empty array  for this scenario
  • Loading branch information
blakekrammes authored Nov 19, 2024
1 parent 5777d3d commit 6f6d5bb
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/components/_classes/component/Component.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
19 changes: 19 additions & 0 deletions test/unit/TextField.unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down Expand Up @@ -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');
Expand Down

0 comments on commit 6f6d5bb

Please sign in to comment.