You need to sign in to do that
Don't have an account?
Ketankumar 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
When I click submit button I get below error.
Please correct me if I any mistake in my code. you help is much appreciated.
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.
Please correct me if I any mistake in my code. you help is much appreciated.
Ishwar Shinde
Try providing value attribute to lightning:input.
Ketankumar Patel
I tried it. It's not working.