Page 1 of 1

validation rule values and date

PostPosted: 02 Jun 2014 07:43
by etwoss
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

Re: validation rule values and date

PostPosted: 02 Jun 2014 10:32
by Alexander Bulei
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.

Re: validation rule values and date

PostPosted: 02 Jun 2014 11:22
by etwoss
Hi

Great!

Thanks very much!

Eric