You need to sign in to do that
Don't have an account?
@ M Coder
lwc js :SIMPLE fix needed - if future date is selected need to throw error message ...
Hi Team ,
Can you fix this if User select a future date say tmoro date it should throw an error in UI. user should only select todays date or previous date
somehow my snippet is working wrong
<lightning-input type="date" name="Date entry" class="dateCls" value={Dateentry} data-name="Dateentry" onchange={handledate} > </lightning-input>
handledate(event){
console.log('event==called=');
if(event.target.name === "Dateentry") {
let psdate = this.template.querySelector(".dateCls");
var today = new Date();
console.log('today==+++=='+today);
if(event.target.value > today)
{
psdate.setCustomValidity("Please Select old Date.");
}
else{
this.SelectedDate = event.target.value;
console.log('this.SelectedDate =+==='+this.SelectedDate );
}
}
}
Can you fix this if User select a future date say tmoro date it should throw an error in UI. user should only select todays date or previous date
somehow my snippet is working wrong
<lightning-input type="date" name="Date entry" class="dateCls" value={Dateentry} data-name="Dateentry" onchange={handledate} > </lightning-input>
handledate(event){
console.log('event==called=');
if(event.target.name === "Dateentry") {
let psdate = this.template.querySelector(".dateCls");
var today = new Date();
console.log('today==+++=='+today);
if(event.target.value > today)
{
psdate.setCustomValidity("Please Select old Date.");
}
else{
this.SelectedDate = event.target.value;
console.log('this.SelectedDate =+==='+this.SelectedDate );
}
}
}
You can try something like below to set custom error message: Related:https://techdicer.com/custom-validation-in-lightning-web-component/
https://www.infallibletechie.com/2022/01/how-to-show-error-message-in-lightning.html
https://medium.com/salesforce-champion/lightning-web-component-custom-validations-4f4d87e119b9
If this information helps, please mark the answer as best. Thank you