You need to sign in to do that
Don't have an account?
Clouding 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
I set the validity as this
evt.getSource().set('v.validity',{valid:false, badInput :true});
this worked fine before Summer' 18 udate.
Awaiting response
hi
please try this
var inputField = component.find('inputField');
inputField.set('v.validity', {valid:false, badInput :true});
The same code works in another org with Spring' 18
>>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 !!