Input Default Error (Deprecated)

ui:inputDefaultError

Deprecated as of API version 47.0. We recommend migrating to Lightning Web Components and using the lightning-input component.

For Use In

Lightning Experience, Experience Builder Sites, Salesforce Mobile App, Lightning Out (Beta), Standalone Lightning App

Deprecation Guidelines 

We recommend using Lightning Web Components whenever possible. When migrating to Lightning Web Components, use lightning-input with built-in field validation.

For more information, see Aura Components in the ui Namespace Are Deprecated.

Usage Overview (Deprecated) 

ui:inputDefaultError is the default error handling for your input components. This component displays as a list of errors below the field. Field-level error messages can be added using set("v.errors"). You can use the error atribute to show the error message. For example, this component validates if the input is a number.

1<aura:component>
2   Enter a number:
3  <ui:inputNumber aura:id="inputCmp" label="number" />
4
5  <ui:button label="Submit" press="{!c.doAction}" />
6
7</aura:component>

This client-side controller displays an error if the input is not a number.

1doAction : function(component, event) {
2    var inputCmp = cmp.find("inputCmp");
3    var value = inputCmp.get("v.value");
4    if (isNaN(value)) {
5        inputCmp.set("v.errors", [{message:"Input not a number: " + value}]);
6    } else {
7        //clear error
8        inputCmp.set("v.errors", null);
9    }
10}

Alternatively, you can provide your own ui:inputDefaultError component. This example returns an error message if the warnings attribute contains any messages.

1<aura:component>
2  <aura:attribute name="warnings" type="String[]" description="Warnings for input text" />
3   Enter a number:
4  <ui:inputNumber aura:id="inputCmp" label="number" />
5
6  <ui:button label="Submit" press="{!c.doAction}" />
7  <ui:inputDefaultError aura:id="number" value="{!v.warnings}" />
8</aura:component>

This client-side controller diplays an error by adding a string to the warnings attribute.

1doAction : function(component, event) {
2    var inputCmp = component.find("inputCmp");
3    var value = inputCmp.get("v.value");
4
5    // is input numeric?
6    if (isNaN(value)) {
7       component.set("v.warnings", "Input is not a number");
8    } else {
9       // clear error
10       component.set("v.warnings", null);
11    }
12}

To create forms for Salesforce objects without using Apex controllers, use lightning:inputField with lightning:recordEditForm, or use lightning:recordForm. To create an input field for different data types, use lightning:input.

Note

Attributes 

NameDescriptionTypeDefaultRequired
bodyThe body of the component. In markup, this is everything in the body of the tag.Aura.Component[]
classA CSS style to be attached to the component. This style is added in addition to base styles output by the component.String
valueThe list of errors strings to be displayed.String[]