+ Start a Discussion
Sisodia SaurabhSisodia Saurabh 

Need to validate fields on default details tab then redirect to new page using Lightning component

Hi All,
I need to validate couple of fields from details tab of a case. if fields are not empty/null then Click on the component button to redirect the page. I know the 2nd part of redirecting but I want to know how can I validate fields on the component click.

Below is the logic which I was trying but I am pretty sure it is not correct way:

Controller
caseValidation : function(component, event, helper){
        debugger;
          var caseId = component.get("v.recordId");
      var action = component.get("c.caseValidationList");
        action.setParams({
            Id : caseId
        }); 
        action.setCallback(this, function(response){ 
            var state = response.getState();
           
            var  cv = response.getReturnValue();
            alert(response.getReturnValue());
            var csonevar;
            if (state === "SUCCESS") {
               for(var c in cv)
                    {
                       csonevar = c.CSOne_Case_Number__c; 
                    }
              alert(csonevar); 
            }
        });
         $A.enqueueAction(action);
    }
Classe returning query
 @AuraEnabled
    public static list<case> caseValidationList(Id Id)
    {
        system.debug('caseId:'+Id);
        List<case> cc = new List<case>();
        if(Id != null || Id != '')
        {
           cc = [Select CSOne_Case_Number__c, OwnerIsQueue__c,Status from case where Id=: Id];
        }
        return cc;
    } 


Thanks in advance

~Srb
Amit Singh 1Amit Singh 1
Hi ,
Refer the below link
https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/js_validate_fields.htm

Also, you can use $A.utility class to validate the fields and return true or false based on the values into the attributes.

Regards,
Amit