Activity Forums Salesforce® Discussions How to show field error in JS Controller in Salesforce?

  • Aditya

    Member
    August 30, 2020 at 6:17 am

    <div>

    1. *errorHandlingController.js*/
    2. {
    3. doAction : function(component) {
    4. var inputCmp = component.find("inputCmp");
    5. var value = inputCmp.get("v.value");
    6. // Is input numeric?
    7. if (isNaN(value)) {
    8. // Set error
    9. inputCmp.set("v.errors", [{message:"Input not a number: " + value}]);
    10. } else {
    11. // Clear error
    12. inputCmp.set("v.errors", null);
    13. }
    14. }
    15. }

    <button data-clipboard-text="/*errorHandlingController.js*/ { doAction : function(component) { var inputCmp = component.find("inputCmp"); var value = inputCmp.get("v.value"); // Is input numeric? if (isNaN(value)) { // Set error inputCmp.set("v.errors", [{message:"Input not a number: " + value}]); } else { // Clear error inputCmp.set("v.errors", null); } } } "></button>
    When you enter a value and click Submit, <samp>doAction</samp> in the contro

    </div>

Log In to reply.

Popular Salesforce Blogs

Popular Salesforce Videos