From 4cf602da9d7cd37e49d7e645f49605e141eb05fb Mon Sep 17 00:00:00 2001 From: tof <> Date: Tue, 5 Feb 2008 14:26:24 +0000 Subject: Fixed #785 --- .../source/prado/datepicker/datepicker.js | 46 +++++++++++++++++++++- framework/Web/UI/WebControls/TDatePicker.php | 6 ++- 2 files changed, 49 insertions(+), 3 deletions(-) (limited to 'framework') diff --git a/framework/Web/Javascripts/source/prado/datepicker/datepicker.js b/framework/Web/Javascripts/source/prado/datepicker/datepicker.js index ade26d26..f502b0d3 100644 --- a/framework/Web/Javascripts/source/prado/datepicker/datepicker.js +++ b/framework/Web/Javascripts/source/prado/datepicker/datepicker.js @@ -83,6 +83,27 @@ Prado.WebUI.TDatePicker.prototype = Object.extend(this,options); Event.observe(this.trigger, triggerEvent, this.show.bindEvent(this)); + + // Listen to change event if needed + if (typeof(this.options.OnDateChanged) == "function") + { + if(this.options.InputMode == "TextBox") + { + Event.observe(this.control, "change", this.onDateChanged.bindEvent(this)); + } + else + { + var day = Prado.WebUI.TDatePicker.getDayListControl(this.control); + var month = Prado.WebUI.TDatePicker.getMonthListControl(this.control); + var year = Prado.WebUI.TDatePicker.getYearListControl(this.control); + Event.observe (day, "change", this.onDateChanged.bindEvent(this)); + Event.observe (month, "change", this.onDateChanged.bindEvent(this)); + Event.observe (year, "change", this.onDateChanged.bindEvent(this)); + + } + + + } }, @@ -430,6 +451,28 @@ Prado.WebUI.TDatePicker.prototype = return false; }, + // Respond to change event on the textbox or dropdown list + // This method raises OnDateChanged event on client side if it has been defined + onDateChanged : function () + { + if (this.options.OnDateChanged) + { + var date; + if (this.options.InputMode == "TextBox") + { + date=this.control.value; + } + else + { + var day = Prado.WebUI.TDatePicker.getDayListControl(this.control).selectedIndex+1; + var month = Prado.WebUI.TDatePicker.getMonthListControl(this.control).selectedIndex; + var year = Prado.WebUI.TDatePicker.getYearListControl(this.control).value; + date=new Date(year, month, day, 0,0,0).SimpleFormat(this.Format, this); + } + this.options.OnDateChanged(this, date); + } + }, + onChange : function() { if(this.options.InputMode == "TextBox") @@ -480,11 +523,12 @@ Prado.WebUI.TDatePicker.prototype = { if (date == null) return; + var old=this.selectedDate; this.selectedDate = this.newDate(date); this.updateHeader(); this.update(); - if (typeof(this.onChange) == "function") + if (old - this.selectedDate !=0 && typeof(this.onChange) == "function") this.onChange(this, date); }, diff --git a/framework/Web/UI/WebControls/TDatePicker.php b/framework/Web/UI/WebControls/TDatePicker.php index 2580ab78..29a57e25 100644 --- a/framework/Web/UI/WebControls/TDatePicker.php +++ b/framework/Web/UI/WebControls/TDatePicker.php @@ -848,12 +848,14 @@ class TDatePicker extends TTextBox * TDatePickerClientScript class. * * Client-side date picker event {@link setOnDateChanged OnDateChanged} - * can be modified through the {@link TDatePicker:: getClientSide ClientSide} + * can be modified through the {@link TDatePicker::getClientSide ClientSide} * property of a date picker. * * The OnDateChanged event is raise when the date picker's date * is changed. - * + * The formatted date according to {@link TDatePicker::getDateFormat DateFormat} is sent + * as parameter to this event + * * @author Wei Zhuo * @version $Id$ * @package System.Web.UI.WebControls -- cgit v1.2.3