Date field validation

rss

Posted by coresoul - Apr 20 ’15 at 03:52

Hi, how do i validate a date field for following:

  • empty validation
  • date greater than today
  • date format validation

Thanks

  • Katy
    Member
    Member for: 7 years 6 months 2 days
    #21 by Katy Oct 11 ’16 at 11:05

    [#20]: Hello Yuriy!

    Thanks this is working. I have a few date and time fields (12) in my form actually and i need to validate each one.That means i need to set 12 different var-s, right?

  • YuriyMedvedev
    Moderator
    Member for: 5 years 3 months 23 days
    #22 by YuriyMedvedev Oct 12 ’16 at 07:13

    The message was removed by a forum moderator.

  • YuriyMedvedev
    Moderator
    Member for: 5 years 3 months 23 days
    #23 by YuriyMedvedev Oct 12 ’16 at 07:28

    [#21]: Hi! Here is an example for two fields.

    fd.onsubmit (function () {
      if (!fd.field('DueDate').value()[0]) {
      alert('Date has not been filled!');
      return false;
     }
     if (!fd.field('AnotherDate').value()[0]) {
      alert('Another Date has not been filled!');
      return false;
     }
    return true;
    });
  • Katy
    Member
    Member for: 7 years 6 months 2 days
    #24 by Katy Oct 12 ’16 at 11:36

    [#20]: I am actually trying to make fields conditionally mandatory as described here: http://formsdesigner.blogspot.com/2014/07/how-to-conditionally-hide-disable-make.html

    The problem is i have two coditions but even with one it is not working so here is my code:

    fd.onsubmit (function () {
    var dt = fd.field('DueDate').value()
    var sdt = fd.field('SetDate').value()

    if (fd.field('Ready').value()) {
    if (fd.field('check1').value()) {
    if (Boolean(dt[0]) && Boolean(sdt[0])) {
    return true;
    }
    else{ alert('Fill the date, please');
    return false;}
    }
    }
    });

     

    The date fields showld be mandatory only if 2 checkboxes are checked. I also tryed:

    if (fd.field('Ready').value() && fd.field('check1').value())

     

    like this:

    fd.onsubmit (function () {
    var dt = fd.field('DueDate').value()
    var sdt = fd.field('SetDate').value()

    if (fd.field('Ready').value() && fd.field('check1').value()) {

    if (Boolean(dt[0]) && Boolean(sdt[0])) {
    return true;
    }
    else{ alert('Fill the date, please');
    return false;}
    }
    });

     

    It is giving the alert when the checkboxes are checked, but if they are not checked i can't save the item at all. I am issing something for sure here....

     

  • Dmitry Kozlov
    Dmitry Kozlov
    Admin
    Member for: 8 years 3 months 29 days
    #25 by Dmitry Kozlov Oct 12 ’16 at 11:40

    [#24]: Yes, you have to return true in the end of your onsubmit handler.

  • Katy
    Member
    Member for: 7 years 6 months 2 days
    #26 by Katy Oct 12 ’16 at 12:56

    [#25]: You mean put one more

    return true

    at the end?

    Or just change places true and false in my script and change the dt[0] to dt [1]? sorry, i am learning everything myself :-)

  • YuriyMedvedev
    Moderator
    Member for: 5 years 3 months 23 days
    #27 by YuriyMedvedev Oct 13 ’16 at 03:19

    [#26]: Yes, after all the condition-blocks (if(){}), in the end of function, before '})' you have to put "return true".

    fd.onsubmit (function () {
    var dt = fd.field('DueDate').value()
    var sdt = fd.field('SetDate').value()
    
    if (fd.field('Ready').value() && fd.field('check1').value()) {
    
     if (Boolean(dt[0]) && Boolean(sdt[0])) {
      return true;
    }
     else{ alert('Fill the date, please');
      return false;}
    }
    return true;
    });
  • Katy
    Member
    Member for: 7 years 6 months 2 days
    #28 by Katy Oct 13 ’16 at 09:31

    [#27]: Thanks a lot! Works great!

Displaying 21 to 28 of 28 messages