• Jyoti Prakash Mishra
  • NEWBIE
  • 0 Points
  • Member since 2018

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 1
    Replies
Hi Folks,

I have set a custom error message using setCustomValidity() in lightning, while clearing it is not working for lightning:input date fields. Seems it is issue from Salesforce. Please let me know if there is any workaround.

Here is the example:
Lightning Component:
<aura:component implements="force:appHostable" >
    <lightning:card footer="Card Footer" title="Hello">
        <lightning:input Label="Name" aura:id="name" value="{!v.acc.Name}" required="true"/>
        <lightning:input type="date" aura:id="date" label="Enter a date" required="true" value="{!v.acc.dhr__Custom_Date_Time__c}"/>
        <lightning:input type="date" label="Enter a date" required="true" value="{!v.acc.dhr__SLA_Expiration_Date_Time__c}"/>
        
        <lightning:button variant="brand" label="Handle Form" title="Brand action" onclick="{! c.handleForm }" />
    </lightning:card>
</aura:component>


Javascript Controller:
({
	handleForm : function(component,event,helper){
        var nameCmp = component.find("name");
        if(!$A.util.isEmpty(component.get("v.acc.Name")) && component.get("v.acc.Name")=="Salesforce"){
        	nameCmp.setCustomValidity("Name cannot be Salesforce") ;
        }else{
            nameCmp.setCustomValidity("") ;
        }
        nameCmp.reportValidity() ;
        
        var dateCmp = component.find("date");
        if(component.get("v.acc.dhr__Custom_Date_Time__c") >   component.get("v.acc.dhr__SLA_Expiration_Date_Time__c")){
        	dateCmp.setCustomValidity("Cannot be future..") ;
        }else{
            alert('clearing..');
            dateCmp.setCustomValidity("") ;
        }
        dateCmp.reportValidity() ;
    }
})