0

I have a record creation form with lightning:recordEditForm tag. I used required = true to some of the inputField values. I have a cancel button at the bottom of the page. When I click 'cancel' button the validation is showing first and then the pop up (quick Action) is closing.I am using event e.force:closeQuickAction to close the pop . Is there a way to close the quick action modal pop up with out any validations ? I tried 'immediate' and 'causesvalidation' attribute on cancel button but it didnt work.

Reason1 and Reason2 are picklist fields

<aura:component implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickActionWithoutHeader" access="global"
                controller = "CaseCreationForm">
    <aura:attribute name="reason1" type="String" default=""/>
    <aura:attribute name="reason2" type="String" default=""/>

    <lightning:card iconName="standard:case" title="Quick Case Create" >
    </lightning:card>
    <div class="slds-has-divider--top slds-m-vertical--large slds-grid--pull-padded-medium"></div>
    <lightning:recordEditForm objectApiName="Case"> 
        <div class="slds-grid">
            <div class="slds-col slds-size_1-of-2">
                <lightning:inputField aura:id="reason1"  fieldName="Reason__c" value = "{!v.reason1}" required ="true"/>
            </div>
            <div class="slds-col slds-size_1-of-2">
                <lightning:inputField aura:id="reason2" fieldName="Reason_2__c" value = "{!v.reason2}" required ="true"/>
            </div>
        </div>
       
        <div class="slds-has-divider--top slds-m-vertical--large slds-grid--pull-padded-medium"></div>
        
        <lightning:button variant="brand" 
                          label="Save" 
                          title="Brand action"
                          type = "submit"
                          onclick="{!c.createCase}"/> &nbsp;&nbsp;&nbsp;
        <lightning:button variant="brand" 
                          label="Cancel" 
                          title="Brand action"
                          type = "submit"
                          onclick="{!c.cancel}"/> 
    </lightning:recordEditForm> &nbsp;&nbsp;&nbsp;
    <aura:html tag="style">
        .cuf-content {
        padding: 0 0rem !important;
        }
        .slds-p-around--medium {
        padding: 0rem !important;
        }
        .slds-modal__content {
        overflow: initial !important;
        height: 80% !important;
        max-height: 80% !important;
        }
        .slds-modal__container{
        max-width: 60% !important;
        width:60% !important;
        }
    </aura:html>
</aura:component>

My controller is as follows

({
    createCase : function(component, event, helper) {
        var reqFlag;
        alert('subject1 -'+component.get("v.subject"));
        alert('subject2 -'+component.find("subject").get("v.value"));
        if($A.util.isEmpty(component.find("reason1").get("v.value"))){
            reqFlag = true;
        }
        if($A.util.isEmpty(component.find("reason2").get("v.value"))){
            reqFlag = true;
        }
        
        console.log('reqFlag-'+reqFlag);
        if(reqFlag){
            alert('false');
        }else{
            
            
            var recordId = component.get("v.recordId");
             var action = component.get('c.saveCase'); 
            console.log('reason 1 -'+component.get('v.reason1'));
            action.setParams({
                
                "Id" : recordId,
                "reason1" :component.get('v.reason1'),
                "reason2" :component.get('v.reason2'),  
                
            });
            action.setCallback(this, function(a){
                var state = a.getState(); // get the response state
                if(state == 'SUCCESS') {
                    var caseId = a.getReturnValue()
                    if(!$A.util.isEmpty(caseId)){
                        var navEvt = $A.get("e.force:navigateToSObject");
                        navEvt.setParams({
                            "recordId": caseId,
                            "slideDevName": "detail"
                        });
                        navEvt.fire();
                    }
                    
                }
            });
            $A.enqueueAction(action);
        }
    },
    cancel : function(component, event, helper){
        var dismissActionPanel = $A.get("e.force:closeQuickAction");
        dismissActionPanel.fire();
    }
})
2
  • 1
    There's no need for immediate=true or something, you just need to use the correct markup. Perhaps if you share your code, we could help you. As is, this is an X-Y problem.
    – sfdcfox
    Aug 20, 2022 at 17:49
  • @sfdcfox I have edited my question and updated with the code that I used.
    – Raham
    Aug 22, 2022 at 4:07

0

You must log in to answer this question.