Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix JavaScript error with min/max value set in DateTime #258

Merged
merged 1 commit into from
Jan 8, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 16 additions & 15 deletions bundles/org.eclipse.rap.rwt/js/rwt/widgets/DateTimeDate.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2008, 2022 Innoopract Informationssysteme GmbH and others.
* Copyright (c) 2008, 2024 Innoopract Informationssysteme GmbH and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
Expand Down Expand Up @@ -28,6 +28,7 @@ rwt.qx.Class.define( "rwt.widgets.DateTimeDate", {
this._long = rwt.util.Strings.contains( style, "long" );
this._drop_down = rwt.util.Strings.contains( style, "drop_down" );
this._internalDateChanged = false;
this._dateDirty = false;
this._weekday = weekdayNames;
this._monthname = monthNames;
this._datePattern = datePattern;
Expand Down Expand Up @@ -343,28 +344,26 @@ rwt.qx.Class.define( "rwt.widgets.DateTimeDate", {
this._dayTextField.setText( "" + this._getDaysInMonth() );
}
}
this._applyLimitRestriction();
// Set the weekday field
this._setWeekday();
var newValue = this._focusedTextField.getText();
if( oldValue != newValue ) {
this._sendChanges();
}
this._applyLimitRestriction();
}
},

_applyLimitRestriction : function() {
var day = parseInt( this._removeLeadingZero( this._dayTextField.getText() ) );
var date = new Date(this._lastValidYear, this._monthInt - 1, day);
if( this._minimum && date.getTime() < this._minimum.getTime() ) {
this.setYear( this._minimum.getFullYear() );
this.setMonth( this._minimum.getMonth() );
this.setDay( this._minimum.getDate() );
}
if( this._maximum && date.getTime() > this._maximum.getTime()) {
this.setYear( this._maximum.getFullYear() );
this.setMonth( this._maximum.getMonth() );
this.setDay( this._maximum.getDate() );
if( !this._dateDirty ) {
var day = parseInt( this._removeLeadingZero( this._dayTextField.getText() ) );
var date = new Date( this._lastValidYear, this._monthInt - 1, day );
if( this._minimum && date.getTime() < this._minimum.getTime() ) {
this._setDate( this._minimum );
}
if( this._maximum && date.getTime() > this._maximum.getTime() ) {
this._setDate( this._maximum );
}
}
},

Expand Down Expand Up @@ -710,7 +709,7 @@ rwt.qx.Class.define( "rwt.widgets.DateTimeDate", {
if( this._minimum ) {
this._minimum.setHours( 0, 0, 0, 0 );
}
this._applySpinnerValue(this._focusedTextField);
this._applySpinnerValue( this._focusedTextField );
this._applyLimitRestriction();
if( this._calendar ) {
this._calendar.setMinimum( this._minimum );
Expand All @@ -722,16 +721,18 @@ rwt.qx.Class.define( "rwt.widgets.DateTimeDate", {
if( this._maximum ) {
this._maximum.setHours( 0, 0, 0, 0 );
}
this._applySpinnerValue(this._focusedTextField);
this._applySpinnerValue( this._focusedTextField );
this._applyLimitRestriction();
if( this._calendar ) {
this._calendar.setMaximum( this._maximum );
}
},

_setDate : function( date ) {
this._dateDirty = true;
this.setYear( date.getFullYear() );
this.setMonth( date.getMonth() );
this._dateDirty = false;
this.setDay( date.getDate() );
},

Expand Down