CGDevTools Forum

Welcome to the Official CGDevTools Support Community Forums.

validation rule values and date

General discussion

by etwoss » 02 Jun 2014 07:43

Hi

I've written an custom validator for checking a selecting a datepicker's date against a param date

I do not get any javascript error but no error is shown when i select the wrong date

I think the reason is how the Rule.Value is filled

How to fill Rule.Value with a date value?

Code: Select all
  TestJS1 :=
'       function(value, element, params) {   ' +
'            if (this.optional(element)) {                                             ' +
'               return true;                                                            ' +
'            }                                                                         ' +
'            var thisDate = $(element).datepicker(''getDate'');                        ' +
'            var thatDate = params[0];                                                 ' +
'            return (thisDate.getTime() < thatDate.getTime());                         ' +
'      } ';

  IWCGJQDatePicker1.JQValidateOptions.AddMethod('dpCompareDateLess', TestJS1,'Minmax' );
  IWCGJQDatePicker1.JQValidateOptions.Enable := True;
  Rule1 := IWCGJQDatePicker1.JQValidateOptions.Rules.Add;
  Rule1.CustomRule := 'dpCompareDateLess';
  Rule1.Value := FormatDateTime(IWCGJQDatePicker1.JQDatePickerOptions.DateFormat,Date);



Eric
etwoss
 
Posts: 1205
Joined: 06 Feb 2014 08:58

by Alexander Bulei » 02 Jun 2014 10:32

Hi Eric,

Please, check this example:

delphi code
var
TestJS1: string;
Rule1: TIWCGJQValidateOptionsRule;
JSonObj: ISuperObject;
d,m,y: Word;
begin
TestJS1 :=
' function(value, element, params) { ' + sLineBreak +
' if (this.optional(element)) { ' + sLineBreak +
' return true; ' + sLineBreak +
' } ' + sLineBreak +
' var thisDate = $(element).datepicker(''getDate''); ' + sLineBreak +
' var thatDate = new Date(params.y,params.m,params.d); ' + sLineBreak +
' return (thisDate.getTime() < thatDate.getTime()); ' +
' } ';

IWCGJQDatePicker1.JQValidateOptions.AddMethod('dpCompareDateLess', TestJS1,'Minmax' );
IWCGJQDatePicker1.JQValidateOptions.Enable := True;
Rule1 := IWCGJQDatePicker1.JQValidateOptions.Rules.Add;
Rule1.CustomRule := 'dpCompareDateLess';

JSonObj:= SO();
DecodeDate(date,y,m,d);
JSonObj.I['y']:= y;
JSonObj.I['m']:= m-1; // JS Month: [0-11]
JSonObj.I['d']:= d;

Rule1.Value := JSonObj.AsJSon;


Best Regards.
Group: Developers | Support Team

  • info [at] cgdevtools.com - General information
  • sales [at] cgdevtools.com - Sales department
  • support [at] cgdevtools.com - Product and Technical Support
User avatar
Alexander Bulei
Site Admin
 
Posts: 3635
Joined: 15 May 2012 08:52
Location: Mealhada, Portugal

by etwoss » 02 Jun 2014 11:22

Hi

Great!

Thanks very much!

Eric
etwoss
 
Posts: 1205
Joined: 06 Feb 2014 08:58


Return to General - Archive

cron

Who is online

Users browsing this forum: No registered users and 1 guest

Contact Us.