Commit 4acbf205 by Jhunel Adam Calub

Merge branch 'feature-WG-484' into 'development-mobile'

WG-484 validdate input See merge request !81
parents 2396ede2 b1bec4d7
...@@ -234,32 +234,44 @@ const validateDate = (validation, value) => { ...@@ -234,32 +234,44 @@ const validateDate = (validation, value) => {
try{ try{
if(mandatory && (value.length===0 || !value.match(/\S/g))) return { valid: false, errors: ['Field is required.'] } if(mandatory && (value.length===0 || !value.match(/\S/g))) return { valid: false, errors: ['Field is required.'] }
if(validdate!=""){
if(validdate === "past"){ if (value.length === 0) {
if (value.length === 0) { return { valid: true };
return { valid: true };
} }
const enteredDateParts = value.split('-'); const enteredDateParts = value.split('-');
if (enteredDateParts.length !== 3) { if (enteredDateParts.length !== 3) {
return { valid: false, errors: ['Invalid date format.'] }; return { valid: false, errors: ['Invalid date format.'] };
} }
const enteredYear = parseInt(enteredDateParts[0]); const enteredYear = parseInt(enteredDateParts[0]);
const enteredMonth = parseInt(enteredDateParts[1]) - 1; // Months are 0-based const enteredMonth = parseInt(enteredDateParts[1]) - 1; // Months are 0-based
const enteredDay = parseInt(enteredDateParts[2]); const enteredDay = parseInt(enteredDateParts[2]);
const enteredDate = new Date(enteredYear, enteredMonth, enteredDay); const enteredDate = new Date(enteredYear, enteredMonth, enteredDay);
const currentDate = new Date();
console.log(currentDate);
if (enteredDate < currentDate) {
return { valid: true }; // The date is in the past
} else {
return { valid: false, errors: ['Future date not allowed.'] };
}
} const currentDate = new Date();
console.log(currentDate);
switch(validdate){
case "past":
if (enteredDate < currentDate) {
return { valid: true }; // The date is in the past
} else {
return { valid: false, errors: ['Only past dates are allowed.'] };
}
case "current":
if (enteredDate = currentDate) {
return { valid: true }; // The date is today
} else {
return { valid: false, errors: ['Only current date is allowed.'] };
}
case "future":
if (enteredDate > currentDate) {
return { valid: true }; // The date is in the future
} else {
return { valid: false, errors: ['Only future dates are allowed.'] };
}
}
}
return { valid: true } return { valid: true }
} catch(err) { } catch(err) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment