[AAE-21797] Datetime widget Min/Max values are checked on a field that is not required (#9524)

* [AAE-21797] Datetime widget Min/Max values are checked on a field that is not required

* update test
This commit is contained in:
Bartosz Sekula
2024-04-08 12:26:06 +02:00
committed by GitHub
parent 5bfef4e3aa
commit 951b8dbe5a
2 changed files with 28 additions and 1 deletions

View File

@@ -313,6 +313,33 @@ describe('FormFieldModel', () => {
expect(form.values['datetime']).toEqual(expectedDateTimeFormat);
});
it('should set the value to null when the value is null', () => {
const form = new FormModel();
const field = new FormFieldModel(form, {
fieldType: 'FormFieldRepresentation',
id: 'datetime',
name: 'date and time',
type: 'datetime',
value: null,
required: false,
readOnly: false,
params: {
field: {
id: 'datetime',
name: 'date and time',
type: 'datetime',
value: null,
required: false,
readOnly: false
}
},
dateDisplayFormat: 'YYYY-MM-DD HH:mm'
});
expect(field.value).toBe(null);
expect(form.values['datetime']).toEqual(null);
});
it('should parse the checkbox set to "true" when it is readonly', () => {
const form = new FormModel();
const field = new FormFieldModel(form, {

View File

@@ -451,7 +451,7 @@ export class FormFieldModel extends FormWidgetModel {
this.value = DateFnsUtils.formatDate(new Date(), this.dateDisplayFormat);
}
const dateTimeValue = new Date(this.value);
const dateTimeValue = this.value !== null ? new Date(this.value) : null;
if (isValidDate(dateTimeValue)) {
this.form.values[this.id] = dateTimeValue.toISOString();