CGDevTools Forum

Welcome to the Official CGDevTools Support Community Forums.

OnChangeMonthYear AJAX Event

by Aggie85 » 10 Feb 2014 15:32

I am using an inline date picker. I added an OnChangeMonthYear event so that I can get the month / year and do a few things.

One of things is that I want to set the date picker's Date property to the first date with an available event. IF I implement the event as an AJAX event, it always resets the month to the first month / year when the date picker was rendered. If I implement the event as NON-AJAX, it works fine but the screen does a full submit.

Any idea on how to fix this?

Thanks!

Aggie85
Aggie85
 
Posts: 273
Joined: 15 May 2013 02:24

by Jorge Sousa » 10 Feb 2014 16:58

Hi Aggie85

Add the following to Design-Time or OnCreate

with IWCGJQDatePicker1.JQDatePickerOptions.OnChangeMonthYear.BrowserParams.Add do
begin
ServerName:= 'Year';
BrowserScript:= 'year';
end;
with IWCGJQDatePicker1.JQDatePickerOptions.OnChangeMonthYear.BrowserParams.Add do
begin
ServerName:= 'Month';
BrowserScript:= 'month';
end;

Then the event will be something like this:

procedure TIWForm12.IWCGJQDatePicker1JQDatePickerOptionsChangeMonthYear(Sender: TObject; AParams: TStringList);

function GetFormatSettings: TFormatSettings;
begin
Result:= CGDatePickerFormatSettings;
Result.ShortDateFormat:= IWCGJQDatePicker1.JQDatePickerOptions.DateFormat;
Result.LongDateFormat:= Result.ShortDateFormat;
Result.DateSeparator:= IWCGJQDatePicker1.JQDatePickerOptions.DateSep;
Result.TwoDigitYearCenturyWindow:= 2;
end;

var
DT: TDateTime;
begin
DT:= EncodeDate(StrToInt(AParams.Values['Year']),StrToInt(AParams.Values['Month']),1);
IWCGJQDatePicker1.JQDatePickerOptions.SetDate(DateToStr(DT,GetFormatSettings));
end;
Best Regards
CGDevTools Develop / Support Team
Home Page: http://www.cgdevtools.com
Jorge Sousa
 
Posts: 4261
Joined: 17 May 2012 09:58

by Jorge Sousa » 10 Feb 2014 17:07

Hi again

This an improved and complete version:


delphi code
procedure TIWForm12.IWCGJQDatePicker1JQDatePickerOptionsChangeMonthYear(Sender: TObject; AParams: TStringList);

function GetFormatSettings: TFormatSettings;
begin
Result:= CGDatePickerFormatSettings;
Result.ShortDateFormat:= IWCGJQDatePicker1.JQDatePickerOptions.DateFormat;
Result.LongDateFormat:= Result.ShortDateFormat;
Result.DateSeparator:= IWCGJQDatePicker1.JQDatePickerOptions.DateSep;
Result.TwoDigitYearCenturyWindow:= 2;
end;

var
DT: TDateTime;
DTS: string;
begin
DT:= EncodeDate(StrToInt(AParams.Values['Year']),StrToInt(AParams.Values['Month']),1);

DTS:= DateToStr(DT,GetFormatSettings);
IWCGJQDatePicker1.JQDatePickerOptions.SetDate(DTS);

CGAddJavaScriptToAjaxResponse(Format('CGSetHiddenInputVal("%s","%s");',[IWCGJQDatePicker1.HTMLName + DateSuffix,DTS]));
end;
Best Regards
CGDevTools Develop / Support Team
Home Page: http://www.cgdevtools.com
Jorge Sousa
 
Posts: 4261
Joined: 17 May 2012 09:58

by Aggie85 » 10 Feb 2014 18:25

Thanks! I will try this when I get back to my office after lunch!

Best Regards,

Aggie85
Aggie85
 
Posts: 273
Joined: 15 May 2013 02:24


Return to JQDatePicker

Who is online

Users browsing this forum: No registered users and 1 guest

Contact Us.