Date field validation
-
- Moderator
- Posts: 33
- Joined: Wed Sep 21, 2016
Hi Katy! Try this one, please:
Code: Select all
fd.onsubmit (function () {
var dt = fd.field('DueDate').value()
if (Boolean(dt[0])) {
alert('Date is filled!');
return true;
}
else{ alert('Fill the date, please');
return false;}
});
-
- Moderator
- Posts: 33
- Joined: Wed Sep 21, 2016
Hi! Here is an example for two fields.
Code: Select all
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;
});
I am actually trying to make fields conditionally mandatory as described here: http://spform.com/office-365/cond ... ynamically
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....
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
- Site Admin
- Posts: 1524
- Joined: Thu Jun 07, 2012
Yes, you have to return true in the end of your onsubmit handler.
-
- Moderator
- Posts: 33
- Joined: Wed Sep 21, 2016
Yes, after all the condition-blocks (if(){}), in the end of function, before '})' you have to put "return true".
Code: Select all
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;
});
-
- Information
-
Who is online
Users browsing this forum: No registered users and 5 guests