CGDevTools Forum

Welcome to the Official CGDevTools Support Community Forums.

How to handle invalid date entered

by rhazell43 » 16 Oct 2013 20:25

Hello,

I'd like to catch when a user has entered an invalid date and ideally notify them.

Assuming I have to detect this myself, my problem come when there doesn't seem to be an approriate event to trap. There's an OnChange JQEvent event but it appears to be triggered infrquently.

Do you have any recommendations.

Thanks in advance.

PS when attached to a datasource it appears that an invalid date is simply cleared (without any warning) which is proving to be quite confusing to end users whom say "I know I entered a date and it just disappear" (albeit in the wrong format) ;)
rhazell43
 
Posts: 80
Joined: 29 Apr 2013 08:27

by jredoc » 03 Jan 2014 21:48

rhazell43

Below is a simple example that will display a notification if the entered date is greater that the current date.

procedure TIWCGFrame_Meds.IWCGJQDatePicker1JQDatePickerOptionsSelect(Sender: TObject; AParams: TStringList);
var
tempSelectedDate: String;
begin
tempSelectedDate := AParams.Values['dateText'];

if StrToDate(tempSelectedDate) > Date then
begin
with IWCGJQNotify1.JQNotificationNotyOptions do
begin
CloseNotification;
Buttons.Clear;
Modal := True;
Text := 'The selected date has not yet occurred';
Layout:= jqnnlCenter;
Type_:= jqnntError;
ShowNotification;
end;

// UserSession.AdsQueryPtMeds.FieldByName('DateInactive').AsDateTime := Date;
UserSession.AdsQueryPtMeds.Cancel;
end;
end;

To implement the above there are three requirements:

1) Implement the following in the IWCGJQDateTimePicker1

with IWCGJQDatePicker1 do
begin
JQDatePickerOptions.GoToCurrent := True;

DataLink.DataSource := UserSession.wwDSQueryPtMeds;
DataLink.FieldName := 'DateInactive';
end;

with IWCGJQDatePicker1.JQDatePickerOptions.OnSelect.BrowserParams.Add do
begin
ServerName := 'dateText';
BrowserScript := 'dateText';
end;


2) create the grid columns in code, the relevant code for this is

iCol:= IWCGJQGrid2.JQGridColumns.Add; // Column 3
iCol.Align:= gaCenter;
iCol.Caption := 'Inactivated';
iCol.Editable := True;
iCol.EditOptions.DatePickerOptions.Disabled := False;
iCol.Formatter := gcfControl;
iCol.FormatOptionsControl.ControlTemplate := IWCGJQDatePicker1;
iCol.Idx := 'DateInactive';
iCol.Name := 'DateInactive';
iCol.Key := False;
iCol.Sortable := True;
iCol.Width := 75;



3) Create the following type in the implementation
type
TIWCGJQGridColUpdateControlEvent = procedure(Sender: TObject; ACol: TIWCGJQGridCol; const ARowId,ACellValue: string) of object;

The explanation for the type declaration comes from the following user group post:
viewtopic.php?f=34&t=345&p=1675&hilit=datepicker#p1675


Note: In the OnSelect event I reset the incorrect date on the server side. I have not yet looked at possibly error trapping the date on the browser side using the JQValidateOptions


I hope this was helpful


John
jredoc
 
Posts: 125
Joined: 11 Jun 2013 03:34


Return to JQDatePicker

Who is online

Users browsing this forum: No registered users and 2 guests

Contact Us.