0

Below is my Lightning Component:

<aura:component implements="force:lightningQuickAction,force:hasRecordId" 
    controller="CreateActionItemController">
<aura:attribute name="recordId" type="Id" />
<aura:attribute name="event" type="Event" />
<aura:handler name="init" value="{!this}" action="{!c.doInit}"/>

<lightning:recordEditForm  aura:id="editForm"
                          objectApiName="Action_Item__c">
    <lightning:messages />
    <lightning:layout multipleRows="true" class="slds-grid_align-center">
        <lightning:layoutItem size="12" class="">
            <lightning:inputField fieldName="Action__c" 
                        value="{!v.event.Action__c}" 
                            disabled="true" style="Display:None;"/>
        </lightning:layoutItem>
        <lightning:layoutItem size="12" class="slds-p-right_medium">
            <lightning:inputField fieldName="Related_Account__c"
                value="{!v.event.WhatId}" disabled="true" style="Display:None;"/>
        </lightning:layoutItem>
        <lightning:layoutItem size="12" class="slds-p-right_medium">
            <lightning:inputField fieldName="Subject__c" 
                required="true" aura:id="subject"/>
        </lightning:layoutItem>
        <lightning:layoutItem size="12" class="slds-p-right_medium}">
            <lightning:inputField fieldName="Type__c" required="true"/>
        </lightning:layoutItem>
        <lightning:layoutItem size="6" class="slds-p-right_medium}">
            <lightning:inputField fieldName="Contact__c" />
        </lightning:layoutItem>
        <lightning:layoutItem size="6" class="slds-p-right_medium">
            <lightning:inputField fieldName="Assigned_To__c"/>
        </lightning:layoutItem>
        <lightning:layoutItem size="6" class="slds-p-right_medium">
            <lightning:inputField fieldName="Priority__c" required="true"/>
        </lightning:layoutItem>
        <lightning:layoutItem size="6" class="slds-p-right_medium">
            <lightning:inputField fieldName="Status__c" required="true"/>
        </lightning:layoutItem>
        <lightning:layoutItem size="12" class="slds-p-right_medium">
            <lightning:inputField fieldName="Due_Date__c" />
        </lightning:layoutItem>
        <lightning:layoutItem size="12" class="slds-p-right_medium">
            <lightning:inputField fieldName="Comments__c"/>
        </lightning:layoutItem>
     </lightning:layout>
</lightning:recordEditForm>
<lightning:button label="Create Action Item" 
                          class="slds-m-top--medium"
                          variant="brand"
                          onclick="{!c.clickCreate}"/>

Below is my JS Handler code for Button Click:

clickCreate : function(component, event, helper) {
    component.find("editForm").submit();
    $A.get("e.force:closeQuickAction").fire();
    $A.get('e.force:refreshView').fire();
}

I have added Required Checks onto the fields but even so when I click on the button, its submits successfully but the out object is not created. To Solve this, I created custom validation Rule for required check. But That too are not working.

Weird things is that, when I remove the two 'Force Actions' I used in JS handler, the Validation Rules works fine.

Am I missing something here?

1 Answer 1

0

i would recommend go through lightning:recordeditform. in your case why required is not fired? because you used Create Action Item lightning:button out of scope from lightning:recordeditform i used inside of lightning:recordeditform so my required attributes successfully fired. and you have to use base actions of lightning:recordeditform in your case i used onsubmit. i didn't change any thing in your controller code. check out below tested code.

CMP

<aura:component implements="force:appHostable,flexipage:availableForAllPageTypes,force:hasRecordId,flexipage:availableForRecordHome,forceCommunity:availableForAllPageTypes" 
        access="global" >
<aura:attribute name="event" type="Event" />
<lightning:card  title="Test">
 <lightning:recordEditForm  aura:id="editForm" density="comfy"
                      objectApiName="Contact"  onsubmit="{!c.clickCreate}">
<lightning:messages />
<lightning:inputField fieldName="Age__c" 
                    value="{!v.event.Action__c}" 
                        required="true" class="slds-col slds-size_1-of-2 slds-p-horizontal_x-small"/>
 <lightning:inputField fieldName="AssistantName"
            value="{!v.event.WhatId}" required="true" class="slds-col slds-size_1-of-2 slds-p-horizontal_x-small" />
 <lightning:inputField fieldName="Level__c" 
            required="true" aura:id="subject" class="slds-col slds-size_1-of-2 slds-p-horizontal_x-small"/>
    <div class="slds-m-top_medium">
       <lightning:button label="Create Action Item" 
                      class="slds-m-top--medium"
                      variant="brand" type="submit"/>
    </div>

   </lightning:recordEditForm>
   </lightning:card>


</aura:component>

enter image description here

2
  • +sdandamud1, thanks for the response. Using type="submit" in the button worked but I want to close the Quick action after the button submits. This form is being called from a Lightning Quick Action button. Commented Nov 21, 2019 at 10:46
  • Please accept my answer/upvote if it works for you. for closing can you come as new Question.
    – sdandamud1
    Commented Nov 21, 2019 at 19:48

You must log in to answer this question.

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