Skip to main content
my Code is  here

 

BoatSearchForm.cmp:-

  1. <aura:component controller="BoatSearchForm" implements="flexipage:availableForAllPageTypes,force:appHostable" access="global" >
  2.     <aura:handler name="init" value="{!this}" action="{!c.doInit}"/>
  3.     <aura:attribute name="boatList" type="List" default="All type" />
  4.       <aura:attribute name="selectedType" type="String" default="All type"/>
  5.     <aura:attribute name="renderNew" type="Boolean" default="true"/>
  6.     <aura:registerEvent name="launchNewBoatForm" type="c:launchNewBoatForm"/>
  7.      <aura:handler name="launchNewBoatForm" event="c:launchNewBoatForm" action="{!c.handleNewBoatForm}"/>
  8.  
  9.     <article class="slds-card slds-m-bottom_medium">
  10.         <div class="slds-media__body">
  11.                   <div class="c-container">
  12.                 <form>
  13.                 <lightning:layout horizontalAlign="center">
  14.                     <lightning:layoutItem >
  15.                         <lightning:select name="selectItem" label="" aura:id="boatTypes"    onchange="{!c.handleChange}">
  16.                             <option value="All type" text="All type"/>
  17.                             <aura:iteration items="{!v.boatList}" var="boattype">
  18.                                 
  19.                                 <option value="{!boattype}" text="{!boattype}"/>
  20.                             </aura:iteration>
  21.                             
  22.                         </lightning:select>
  23.                     </lightning:layoutItem>
  24.                     &nbsp;
  25.                     <lightning:layoutItem ><br/>
  26.                         <lightning:button variant="brand" label="Search" onclick="{!c.onFormSubmit}" />
  27.                     </lightning:layoutItem>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  28.                     <lightning:layoutItem ><br/>
  29.                         <aura:if isTrue="{!v.renderNew}">
  30.                             <lightning:button variant="neutral" label="New"  onclick="{!c.newBoat}" />
  31.                         </aura:if>
  32.                     </lightning:layoutItem>
  33.                 </lightning:layout>
  34.                 </form>
  35.                 
  36.             </div>
  37.         </div>
  38.     </article>

</aura:component>

 

BoatSearchFormControllerjs:-

  1. ({
  2.     doInit: function(component, event, helper) {
  3.        // helper.createRecord(component, event, helper);
  4.         helper.fetchPickListVal(component, event, helper);
  5.     },
  6.     handleNewBoatForm: function(component, event, helper){
  7.         console.log("handleNewBoatForm handler called.")
  8.         var boatTypeId = component.get("v.selectedType");
  9.  
  10.         console.log(boatTypeId);
  11.         var createNewBoat = $A.get("e.force:createRecord");
  12.         createNewBoat.setParams({
  13.             "entityApiName": "Boat__c",
  14.         })
  15.         if(! boatTypeId==""){
  16.             createNewBoat.setParams({
  17.                 "defaultFieldValues": {'BoatType__c': boatTypeId}
  18.            })
  19.         }
  20.         createNewBoat.fire();
  21.     },
  22.      newBoat : function(component, event, helper){
  23.         var boatTypeId = component.get("v.selectedType");
  24.         console.log("New button pressed " + boatTypeId);
  25.         var requestNewBoat = component.getEvent("launchNewBoatForm");
  26.         requestNewBoat.setParams({"boatTypeId": boatTypeId});
  27.         requestNewBoat.fire();
  28.     },
  29.     search : function(component, event, helper) {
  30.         console.log('selectedType', component.get("v.selectedType"));
  31.        var selectedType = component.get("v.selectedType");
  32.     }
  33.     ,
  34.     handleChange : function(component, event, helper){
  35.               console.log('boatTypes',component.find("boatTypes").get("v.value"));
  36.            component.set("v.selectedType", component.find("boatTypes").get("v.value"));
  37.  
  38.     },

})

 

BoatSearchResults.cmp

  1. <aura:component controller="BoatSearchResults" implements="flexipage:availableForAllPageTypes,force:appHostable" access="global" >
  2.     <aura:attribute name="boats" type="List" />
  3.         <aura:handler name="init" value="{!this}" action="{!c.doSearch}" />
  4.     <aura:attribute name="boatTypeId" type="String" />
  5.  
  6.      <aura:method name="search" >
  7.             <aura:attribute name="boatTypeId" type="Id"/>
  8.     </aura:method>
  9.      
  10.    <lightning:layout multipleRows="true">
  11.  
  12.             <aura:if isTrue="{!v.boats.length > 0}">
  13.  
  14.             <aura:iteration items="{!v.boats}" var="bot">
  15.                 <lightning:layoutItem flexibility="auto" padding="around-small">
  16.                 <c:BoatTile boat="{!bot}" />
  17.                 </lightning:layoutItem>
  18.              </aura:iteration>
  19.  
  20.             <aura:set attribute="else">
  21.                 <div class="slds-align_absolute-center">
  22.                     No boats found
  23.                 </div>
  24.             </aura:set>
  25.         </aura:if>
  26.     </lightning:layout>

</aura:component>

  1. BoatSearchResultsController.js:
  2. ({
  3.     doSearch : function(component, event, helper) {
  4.            helper.onSearch(component);
  5.     },
  6.     search: function(component, event, helper){
  7.       
  8.         var params = event.getParam('arguments');
  9.         console.log("boatTypeId extracted: " + params.boatTypeId);
  10.         component.set("v.boatTypeId", params.boatTypeId);
  11.         
  12.         helper.onSearch(component);
  13.         return "search complete.";
  14.     },

})

 

BoatSearchResultHelper.js

 

({

 

     onSearch : function(component){

 

      

 

        var action = component.get("c.getBoats");

 

         action.setParam({"boatTypeId":""});

 

   

 

        action.setCallback(this, function(response){

 

          console.log(response.getReturnValue());

 

          

 

            var status = response.getState();

 

            if(status === "SUCCESS") {

 

                if(! $A.util.isEmpty(response.getReturnValue())){

 

                    component.set("v.boats",response.getReturnValue());

 

                } else {

 

                     component.set("v.recordError","No boats found");

 

                }

 

            }

 

        });

 

        $A.enqueueAction(action);

 

    }

 

})

 

BoatSearch.cmp

  1. <aura:component implements="flexipage:availableForAllPageTypes,force:appHostable" access="global">
  2.     <aura:handler name="formsubmit"  event="c:FormSubmit"   action="{!c.onFormSubmit}" />
  3.  
  4.   <lightning:card title="Find a Boat" class="slds-m-top_10px">
  5.     <c:BoatSearchForm />
  6.        </lightning:card>
  7.    <lightning:card title="Matching Boats">
  8.     <c:BoatSearchResults aura:id="BoatSearchResults"/>
  9.  </lightning:card>
  10. </aura:component>

BoatSearchController.js:-

 

({

  1.     onFormSubmit : function(component, event, helper){
  2.  
  3.         var formData = event.getParam("formData");
  4.         var boatTypeId = formData.boatTypeId;
  5.         var BSRcmp = component.find("BoatSearchResults");
  6.         var auraMethodResult = BSRcmp.search(boatTypeId);
  7.     },
  8. })

FormSubmit.evt

  1. <aura:event type="COMPONENT" description="Event template" >
  2.      <aura:attribute name="formData" type="Object[]"/>
  3. </aura:event>
4 respostas
  1. 3 de out. de 2019, 10:45
    I've just passed it. The problem was in that I placed onFormSubmit function in BoatSearchFormHelper instead of BoatSearchFormController. I moved it and in worked. 

     

    But at the same time I can't find in your code onFormSubmit function that would work with FormSubmit event at all... You didn't write it yet?
0/9000