Skip to content

Commit e1645e1

Browse files
authored
Create validateReturndate.js
1 parent 4ef7cbd commit e1645e1

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
function onChange(control, oldValue, newValue, isLoading) {
2+
if (isLoading || newValue == '') {
3+
return;
4+
}
5+
var u_start_date = g_form.getValue('u_start_date'); //start date validation to check to see whether filled or not
6+
if (!u_start_date) {
7+
g_form.clearValue('u_return_date');
8+
g_form.showFieldMsg('u_return_date', 'Please enter start date', 'error');
9+
} else {
10+
var startTime = getDateFromFormat(u_start_date, g_user_date_format); //converting to js date object
11+
var returnTime = getDateFromFormat(newValue, g_user_date_format);
12+
var selectedStartDate = new Date(startTime);
13+
var returnDate = new Date(returnTime);
14+
var returnDateDifference = (returnDate - selectedStartDate) / 86400000; //converting the diff between the dates to days by dividing by 86400000
15+
if (returnDateDifference > 180) {
16+
g_form.clearValue('u_return_date');
17+
g_form.showFieldMsg('u_return_date', 'Select Return Date within 6 months from Start Date', 'error');
18+
} else if (returnDateDifference < 1) {
19+
g_form.clearValue('u_return_date');
20+
g_form.showFieldMsg('u_return_date', 'Select Return Date in future than Start Date', 'error');
21+
}
22+
}
23+
}

0 commit comments

Comments
 (0)