Skip to content

Commit 19e1e33

Browse files
committed
enh
1 parent 0d4c079 commit 19e1e33

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

services/static-webserver/client/source/class/osparc/ui/form/DateTimeField.js

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,15 @@ qx.Class.define("osparc.ui.form.DateTimeField", {
2525

2626
this._setLayout(new qx.ui.layout.HBox(5));
2727

28+
this.set({
29+
maxHeight: 26
30+
});
31+
2832
// Date selector
33+
const dateFormat = new qx.util.format.DateFormat("dd/MM/yyyy");
2934
this.__dateField = new qx.ui.form.DateField();
30-
this.__dateField.set({
31-
minimumDate: new Date() // forbid past dates
32-
});
35+
this.__dateField.setDateFormat(dateFormat);
36+
this.__dateField.setValue(new Date());
3337
this._add(this.__dateField);
3438

3539
// Hour selector
@@ -75,21 +79,26 @@ qx.Class.define("osparc.ui.form.DateTimeField", {
7579

7680
__updateValue: function() {
7781
const date = this.__dateField.getValue();
82+
const now = new Date();
83+
7884
if (date) {
85+
// Prevent past dates
86+
if (date < now.setHours(0,0,0,0)) {
87+
this.__dateField.setValue(new Date());
88+
return;
89+
}
90+
7991
const newDate = new Date(date.getTime());
8092
newDate.setHours(this.__hourSpinner.getValue());
8193
newDate.setMinutes(this.__minuteSpinner.getValue());
8294

83-
const now = new Date();
84-
85-
// If same day, ensure time is not in the past
95+
// If today, prevent past time
8696
const isToday =
8797
date.getFullYear() === now.getFullYear() &&
8898
date.getMonth() === now.getMonth() &&
8999
date.getDate() === now.getDate();
90100

91101
if (isToday && newDate < now) {
92-
// Snap to current time if invalid
93102
this.__hourSpinner.setValue(now.getHours());
94103
this.__minuteSpinner.setValue(now.getMinutes());
95104
this.setValue(now);

0 commit comments

Comments
 (0)