Forum


Calc Builder Support

Calc Builder support
Forums
Public write access is disabled. Please login

Two date validation 10.06.2017 05:00

Hello,
How should I validate datapicker for the two dates?
My code is working wrong.


CB.validator.addMethod("cb_greaterthan", function(element) {
var startDate = CB("input[fldname=baslangictarihi]").val();
var enddate = CB("input[fldname=bitistarihi]").val();
return Date.parse(startDate) >= Date.parse(enddate) || enddate== "";
},CB.validator.format("İşten çıkış tarihiniz, işe giriş tarihinizden büyük olmalı. Lütfen düzeltiniz.")
);
CB.validator.addClassRules({
cb_greaterthan : { cb_greaterthan : true }
});

Re: Two date validation 11.06.2017 18:59

Hello,
in order to have the custom validation working you must ensure you have set your custom

cb_greaterthan

validation at the fields configuration (css class, for the 2 fields). Then we suggest to force the validator to a fixed (false) value to check if it's being properly lauched:

return false;

and if this works ok, then the problem can be at the date parsing, because this may depend on your local date format, you can alert(startDate) to confirm you're getting the right values and in which format. If you can share which are the results at this point we can help you with a code tip to parse&compare properly the 2 values.

Thanks, regards
Moonsoft Team
www.moonsoft.es

Re: Two date validation 13.06.2017 23:35

Thank you very much for your support. Would you please examine the my calculator?
My xml file:
https://drive.google.com/open?id=0By8I2I6cYe_cS0tURzFSbkVpWmc

Re: Two date validation 24.06.2017 23:45

Please, give an idea:(

Re: Two date validation 26.06.2017 12:17

Hi,
sorry for the delay, we hadn¡t received your last update. Feel free to update any ticket or forum thread if you don't receive response within 48 business hours. Regarding your code, the function date parse you're using doesn't work properly with the date format you're configuring for your fields. This code works properly here:


CB.validator.addMethod("cb_greaterthan", function(element) {
var startDate = CB("input[fldname=baslangictarihi]").val();
var enddate = CB("input[fldname=bitistarihi]").val();

if(enddate=="") return true;
var parts = startDate.split('/');
// new Date(year, month [, day [, hours[, minutes[, seconds[, ms]]]]])
startDate =new Date(parts[2], parts[1]-1, parts[1]);
parts = enddate .split('/');
// new Date(year, month [, day [, hours[, minutes[, seconds[, ms]]]]])
enddate =new Date(parts[2], parts[1]-1, parts[1]);

return startDate
Moonsoft Team
www.moonsoft.es

Re: Two date validation 28.06.2017 21:53

Thanks a lot...

I solved the problem with your help


CB.validator.addMethod("cb_greaterthan", function(element) {
var startDate = CB("input[fldname=baslangictarihi]").val();
var enddate = CB("input[fldname=bitistarihi]").val();

var parts1 = startDate.split('/');
var parts2 = enddate.split('/');


if(parts1[2] mat("İşten çıkış tarihiniz, işe giriş tarihinizden büyük olmalı. Lütfen düzeltiniz.") // message
);
CB.validator.addClassRules({
cb_greaterthan : { cb_greaterthan : true }
});
Are you satisfied with our products/services/support?
Please help us to keep improving, add a review at  joomla extensions site and  magento connect
FaLang translation system by Faboba

Our clients' feedback