Clear Error
Collapse
Expand
Menu Focus Change (Deprecated)
Menu Select (Deprecated)
Menu Trigger Press (Deprecated)
Validation Error (Deprecated)
LWC Developer Guide
SLDS 1
SLDS 2
ui:clearErrors
Indicates that validation errors are cleared.
For Use In
Lightning Experience, Experience Builder Sites, Salesforce Mobile App
This event is fired when validation errors on an input field are cleared. To set a handler for the ui:clearErrors event, use the onClearErrors attribute on a component that extends ui:input, such as ui:inputText and ui:inputNumber.
The following ui:inputNumber component displays an error message when the number entered is less than 10. It displays an alert when the error message is cleared.
1<aura:component>
2 <aura:attribute name="myNumber" type="integer" default="10" />
3 <ui:inputNumber
4 aura:id="number"
5 label="Enter a number: "
6 value="{!v.myNumber}"
7 onClearErrors="{!c.handleClearErrors}"
8 />
9 <ui:button label="Validate" press="{!c.handleValidate}" />
10</aura:component>Here’s the client-side controller that handles the input validation and clearing of the error message.
1({
2 handleValidate: function (cmp, evt, helper) {
3 var num = cmp.find("number");
4 var val = num.get("v.value");
5 if (val < 10) {
6 num.set("v.errors", [{ message: "Enter a number more than 10" }]);
7 } else {
8 num.set("v.errors", null);
9 }
10 },
11
12 handleClearErrors: function (cmp, evt, helper) {
13 alert("Error has been cleared");
14 },
15});If you’re using this event with a component other than those that extend ui:input, register the event first.
1<aura:registerEvent
2 name="onClearErrors"
3 type="ui:clearErrors"
4 description="The event fired when validation errors are cleared."
5/>For more information, see the Lightning Aura Components Developer Guide.
