+ Start a Discussion
Ketankumar PatelKetankumar Patel 

Getting Error while validating field

It's strange I followed the salesforce document but I am getting error on validating lightning input field. 

Here is my code.

CustomErrorHandling.cmp
<aura:component>
    
      <lightning:input aura:id="inputCmp"
                           label="Please Enter a Number"
                           name="inputCmp" /><br/>
    <lightning:button label="Submit" onclick="{!c.doAction}"/>
</aura:component>
CustomErrorHandling.js
({
	/*errorHandlingCustomController.js*/

    doAction : function(component, event) {
        var inputCmp = component.find("inputCmp");
        var value = inputCmp.get("v.value");

        // is input numeric?
        if (isNaN(value)) {
            inputCmp.set("v.errors", [{message:"Input not a number: " + value}]);
        } else {
            inputCmp.set("v.errors", null);
        }
    },

    handleError: function(component, event){
        /* do any custom error handling
         * logic desired here */
        // get v.errors, which is an Object[]
        var errorsArr  = event.getParam("errors");
        for (var i = 0; i < errorsArr.length; i++) {
            console.log("error " + i + ": " + JSON.stringify(errorsArr[i]));
        }
    },

    handleClearError: function(component, event) {
        /* do any custom error handling
         * logic desired here */
    }
})

When I click submit button I get below error.

User-added image

Please correct me if I any mistake in my code. you help is much appreciated.
Ishwar ShindeIshwar Shinde
Try providing value attribute to lightning:input.
Ketankumar PatelKetankumar Patel
I tried it. It's not working.