0

I have a requirement wherein the user enters a data and if the date is more than 30 days then I show a validation error msg in lightning component. Below is the code I have done

<aura:attribute name="todayDate" type="date" description="date" default="" />
<lightning:input type="date" aura:id="IssuedDate" 
name="IssuedDate" label="Issued Date to" max="{!v.todayDate}" 
messageWhenRangeOverflow="Service To Date cannot be greater than 30 days the current date" />

In the Load event of lightning component I am doing as follows:

var todayDate = $A.localizationService.formatDate(new Date(), "YYYY-MM-DD"); 
component.set("v.todayDate",d.setMonth(1));

But its not working as expected. Please let me know.

0

Why don't you use the standard valid rules in object manager? Create a new rule which is true when (issuedDate - Date.today() > 30), and set the error message to "Service To Date cannot be greater than 30 days the current date". That should work well when user subimt the form and got the error message which showed in the lightning-messages part or the field part based on your selection.

1
  • I am using javascript to handle this, I am not storing anything in backend, – Krishna Casukhela Apr 9 at 6:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.