Moonsoft Software Solutions

Two date validation

Started 10 Jun 2017 · 5 replies

  1. mehmethocam1
    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 }
    });
  2. Moonsoft support
    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
  3. mehmethocam1
    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
  4. mehmethocam1
    Please, give an idea:(
  5. Moonsoft support
    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
  6. mehmethocam1
    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 }
    });

Still stuck?

Customers with an active license can open a support ticket.

Log in to open a ticket