0

My requirement is when picklist value is selected, an inputfield shouldn't be blank.

Pls find my code below :

controller :

 saveAction: function(component, event, helper){
        helper.validateForm(component,event,helper);
 }

Helper :

validateForm: function(component){
      var message = event.getParam("Message");
      var recTypes = component.get("v.selRecTypeName");
       var recTypId = component.get("v.selectedRecType");
       var contributions = component.get("v.contributions");
       var recTypId = component.get("v.selectedRecType");
        for(var i=0; i<contributions.length; i++){
                if(recTypId == contributions[i].value)
                component.set("v.GANumber", contributions[i].GA_Number__c);
                }

        var validData = true; //Flag
        var pklstField = component.get("v.fundTypes");
        var pklstFieldData = pklstField.get("v.value");
        var txareaField = component.get("v.GANumber");
        var txareaFieldData = txareaField.get("v.value");


    if(((pklstFieldData == "Emp1") || (pklstFieldData == "Emp2") || (pklstFieldData == "Emp3")) && txareaFieldData == null){
        validData = false;
        txareaField.set("v.errors", [{message:"Text area cannot be empty"}]);
    } else {
        txareaField.set("v.errors", null);
    }
     return validData;
   },

But, when i try to click on Save button, getting error like : Uncaught exception: helper not defined.

( it shows 10 seconds, then close the Edit page) pls check and let me know, how to fix this Thanks

1
  • You should not pass in the helper to the helper function. But you should pass the event. otherwise this var message = event.getParam("Message"); won't work. Commented Mar 27, 2020 at 20:03

1 Answer 1

0

The issue is coming from the validateForm function definition.

From the controller.js, the validateForm function is called with 3 parameters:

helper.validateForm(component,event,helper);

But in the helper.js, the validateForm function is accepting only 1 parameter:

validateForm: function(component){...}

To fix this, change the validateForm function definition to accept the 3 parameters like this:

validateForm: function(component,event,helper){...}

Hope this helps

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .