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
Clouding Around 10Clouding Around 10 

Issue with lightning:input validation after Summer' 18 update

I am trying to set a lightning input field as invalid through a controller method in a lightning component.
I set the validity as this
evt.getSource().set('v.validity',{valid:false, badInput :true});
this worked fine before Summer' 18 udate.
Awaiting response
jane1234jane1234

hi 

please try this 
var inputField = component.find('inputField');

 inputField.set('v.validity', {valid:false, badInput :true}); 

Clouding Around 10Clouding Around 10
Hi @Seethal I tried doing it this way as well, same issue persists. This is specifically with Summer' 18.
The same code works in another org with Spring' 18
Joe Ortiz 1Joe Ortiz 1
Is this filed as a Known Issue? I'm having trouble finding it.
Thimmaiah VanganurThimmaiah Vanganur
Hello All,
 
>>Validity is a read-only property, prior versions weren't enforcing this. If you want to set a custom error you need to use myInput.setCustomValidity('My error message'); myInput.showHelpMessageIfInvalid(); 

>> If you want to reset the custom error then do myInput.setCustomValidity(''); This (validity/setCustomValidity) is exactly how a native html5 input works as well. 

>>See documentation: https://developer.salesforce.com/docs/component-library/bundle/lightning:input/documentation (under Custom Validity Error Messages). 

>> Note that the examples are using reportValidity() instead of showHelpMessageIfInvalid() -- the two are equivalent, reportValidity() is just aligning with standards, as that's what a native input uses per Constraint Validation API https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#the-constraint-validation-api 

Thanks !!