Date field validation
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
-
KatyMemberMember for: 9 years 2 months 10 days
[#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?
-
YuriyMedvedevModeratorMember for: 6 years 11 months 30 days
The message was removed by a forum moderator.
-
YuriyMedvedevModeratorMember for: 6 years 11 months 30 days
[#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; });
-
KatyMemberMember for: 9 years 2 months 10 days
[#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 KozlovAdminMember for: 10 years 4 days
[#24]: Yes, you have to return true in the end of your onsubmit handler.
-
KatyMemberMember for: 9 years 2 months 10 days
[#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 :-)
-
YuriyMedvedevModeratorMember for: 6 years 11 months 30 days
[#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; });
-
KatyMemberMember for: 9 years 2 months 10 days
[#27]: Thanks a lot! Works great!