You need to sign in to do that
Don't have an account?
IntroAmmy
If age is more than 18 years then few field should be hide in page using lightning component
I have created lightning component and 6 fields there, one date field is also there
how can we do that if age is more than 18 years then 2 fields shoud be hide.
Can please someone help me on that...
Thanks in advance
how can we do that if age is more than 18 years then 2 fields shoud be hide.
Can please someone help me on that...
Thanks in advance
Try The Below Code Please Mark It As Best Answer If It Helps
Thank You!
All Answers
handleDOB(event){
this.showFields = this.dateDiff(event.target.value);
}
dateDiff(fromDate)
{
const date1 = new Date(fromDate);
const date2 = new DateTime.Now;
const diffTime = Math.abs(date2 - date1);
const diffDays = Math.ceil(diffTime / (1000 * 60 * 60 * 24));
console.log(diffTime + " milliseconds");
console.log(diffDays + " days");
if((diffDays/365) <=2){ //Might be need to change here, remove hardcoded here and calculate total number of days in current year.
return true;
}
else return false;
}
HTML:
<lightning-input type="date" id="personDateOfBirth" label="DOB :" value={DateOfBirth} onchange={handleDOB}>
<lightning-input id="pastEmpRecordName" type="text" required="true" label="Field 1"></lightning-input>
<lightning-input if:true={ showFields } id="pastEmpRecordTitle" type="text" required="true" label="Field 2"></lightning-input>
<lightning-input if:true={ showFields } id="pastEmpRecordPhone" type="text" required="true" label="Field 3"></lightning-input>
try following dummy component.
let me know if it helps you and marking it as best.
Thank You
Try The Below Code Please Mark It As Best Answer If It Helps
Thank You!