4

My purchaseOrderSearchComponent.cmp

<aura:component controller="purchaseOrderSearchControllerRe" implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes" access="global">
<aura:attribute name="date" type="Date" access="GLOBAL"/>
<aura:handler name="change" value="{!v.date}" action="{!c.dateChange}"/>

<div class="slds-form-element">
           <div class="slds-form-element__control">
             <ui:inputDate aura:id="orderDate" label="Order Date"
                               class="slds-input"
                               labelClass="slds-form-element__label"
                               change="{!c.dateChange}" 
                               value="{!v.date}"
                               displayDatePicker="true"/>
 </div>
 </div>
<div class="slds-form-element">

            <ui:button label="Submit" 
                       class="slds-button slds-button--neutral"
                       labelClass="label"
                       press="{!c.searchPO}"/>
 </div>

My purchaseOrderSearchComponentcontroller.js

 ({
searchPO: function(component, event, helper){
         helper.getPurchaseOrderList(component);

    //Set up the callback

  },
dateChange: function(component, event, helper){
               console.warn("dateChange");
               var date = component.get("v.date");
               console.warn("date is: ", date);
             }
)}

My purchaseOrderSearchComponentHelper.js

    ({
    getPurchaseOrderList: function(component) {

        var ordrdate = component.get("v.date");

        console.log('ordrdate='+ordrdate);
        var action = component.get("c.getSearchList");

        action.setParams({  "ordrdate" : ordrdate });
    //Set up the callback
    var self = this;
    action.setCallback(this, function(actionResult) {
     //do stuffs; 
    });
    $A.enqueueAction(action);
  }
})

My purchaseOrderSearchControllerRe apex class

    @AuraEnabled
  public static List<Purchase_Order__c> getSearchList(Date ordrdate) {

    System.debug('ordrdate='+ordrdate);
}

I am getting ordrdate=null in debug startement. But in console.log statement I am getting a date value. What wrong am i doing? I have tried a lot to figure out...But all in vain. Any help!!!

  • In the console log, are you getting the correct date in both logs? – Fernando Gavinho Jul 26 '16 at 8:45
  • Yes. I am getting the correct date. – TANAY RAY Jul 26 '16 at 9:07
6

First of all your controller is not closed properly. The actual method is

({
    //..............
})

Modify the dateChange methods as below.

dateChange: function(component, event, helper){
        var dateField = component.find("orderDate");
        var date = dateField.get("v.value");
        component.set("v.date", date);
}

Lastly, change the parameter type from Date to String in apex. It can be converted to date using

Date.valueOf(ordrdate);
  • 1
    dateChange: function(component, event, helper){ var dateField = component.find("orderDate"); var date = dateField.get("v.value"); component.set("v.date", date); } worked for me with a little change component.set("v.date", date) instead of _ component.get("v.date", date);_ . I think that's a typo you made. It is working. A great help. Thanks a lot @JunaidPKhader – TANAY RAY Jul 26 '16 at 11:27
  • That means it is not possible to pass a an argument of type Date to a @Auraenabled method. Am i right?? – TANAY RAY Jul 26 '16 at 11:31
  • Yes you are right. – Junaid P Khader Jul 26 '16 at 11:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.