function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Anindya Halder 17Anindya Halder 17 

reportValidity() does not clears any displayed error if the input is valid

I am trying to display custom error message in lightning:input field using setCustomValidity() and reportValidity().
Exactly as given in the documentation here :- https://developer.salesforce.com/docs/component-library/bundle/lightning:input/documentation
 
({
    validateRenewaldate : function(component, event) {
        var inputCmp = component.find("inputCmp");
        var value = inputCmp.get("v.value");

        var calcutedValue = <some calculation here>;
        

        // is input valid text?
        if (value > calcutedValue) {
            inputCmp.setCustomValidity("”);
        } else {
            inputCmp.setCustomValidity("");
        }
        inputCmp.reportValidity(); 
    })

It displays the right error message when the input is invalid . But it does not remove that error essage when a valid data is entered.
I have even used checkValidity() to confirm that its actually valid.

I have verified this in Chrome and Firefox

In the documentation it clearly says reportValidity()  clears displayed wrrors when the input is valid but its not working that way.

Is there any way around this ?

P.S we can not se anything validity object because that is read-only now.
Anindya Halder 17Anindya Halder 17
P.S we can not set any properties in  "validity" object because that is read-only now.
Joe Markey 6Joe Markey 6
I have a lightning:input control and I'm using custom JavaScript to implement custom validation. I'm able to add my custom validation error message using:
cmp.find("dynamicTemplateField").setCustomValidity($A.get("$Label.c.Dynamic_Merge_Field_Validation_Text"));
cmp.find("dynamicTemplateField").reportValidity();
return false;

I'm able to then clear this custom validation error message using:
cmp.find("dynamicTemplateField").setCustomValidity("");
cmp.find("dynamicTemplateField").reportValidity();

Here is the lightning:input that is validated:
<lightning:input aura:id="dynamicTemplateField" disabled="{!!v.isDynamicTemplates}" label="{!$Label.c.Dynamic_Merge_Field_Text}" onblur="{!c.handleBlurMergeField}" placeholder="{!$Label.c.Enter_Merge_Field_Text}" value="{!v.inputMergeField}" variant="label-hidden" />