CalcBuilder Forum

Two date validation

User mehmethocam1 2017-06-10 05:00:10

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").val();
var enddate = CB("input").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 }
});

Moonsoft support 2017-06-11 18:59:31

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

User mehmethocam1 2017-06-13 23:35:57

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

User mehmethocam1 2017-06-24 23:45:41

Please, give an idea:(

Moonsoft support 2017-06-26 12:17:40

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").val();
var enddate = CB("input").val();

if(enddate=="") return true;
var parts = startDate.split('/');
// new Date(year, month ]]]])
startDate =new Date(parts, parts-1, parts);
parts = enddate .split('/');
// new Date(year, month ]]]])
enddate =new Date(parts, parts-1, parts);

return startDate

User mehmethocam1 2017-06-28 21:53:49

Thanks a lot...

I solved the problem with your help


CB.validator.addMethod("cb_greaterthan", function(element) {
var startDate = CB("input").val();
var enddate = CB("input").val();

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


if(parts1 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 }
});

...
Support/development 10 hours

Get a bigger amount of hours for more complex tasks and get a 10% discount

Buy now!
...
List Manager

Build different lists for your site

Buy now!