Advertisement
Guest User

Untitled

a guest
Oct 27th, 2016
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.48 KB | None | 0 0
  1. public class DateIssueCont {
  2. @AuraEnabled
  3. public static void saveRecord( Custom_Object__c rec ){
  4. insert rec;
  5. }
  6. }
  7.  
  8. <aura:application controller="DateIssueCont">
  9. <aura:attribute name="record" type="Custom_Object__c" default="{'sobjectType': 'Custom_Object__c', 'Date__c': ''}" />
  10. <ui:inputDate value="{!v.record.Date__c}" displayDatePicker="true" />
  11. <aura:handler name="init" value="{!this}" action="{!c.init}"/>
  12. <div aura:id="errors" class="slds-hide">
  13. <div class="slds-form-element" >
  14. <div class="slds-form-element__control">
  15. <ui:message title="Error" severity="error" >
  16. <ui:outputText aura:id="ErrorMessage" value=""/>
  17. </ui:message>
  18. </div>
  19. </div>
  20. </div>
  21. <button class="slds-button slds-button--neutral slds-button--brand" onclick="{!c.perform}">Perform Business Logic</button>
  22. </aura:application>
  23.  
  24. ({
  25. init : function(component, event, helper) {
  26. component.set("v.record.Date__c", '2016-1-1' );
  27. },
  28.  
  29. perform : function(component, event, helper) {
  30. var rec = component.get( 'v.record' );
  31. var saveRecord = component.get( "c.saveRecord" );
  32. saveRecord.setParam( "rec", rec );
  33. saveRecord.setCallback(this, function(response) {
  34. var state = response.getState();
  35. if (component.isValid() && state === "SUCCESS") {
  36. } else if (state === "ERROR"){
  37. var errors = response.getError();
  38. if (errors && errors[0] && errors[0].message) {
  39. $A.util.removeClass( component.find("errors"), "slds-hide");
  40. component.find("ErrorMessage").set("v.value", errors[0].message);
  41. }
  42. if (errors && errors[0] && errors[0].pageErrors && errors[0].pageErrors[0] && errors[0].pageErrors[0].message ) {
  43. $A.util.removeClass( component.find("errors"), "slds-hide");
  44. component.find("ErrorMessage").set("v.value", errors[0].pageErrors[0].message);
  45. }
  46. if (errors && errors[0] && errors[0].fieldErrors ) {
  47. $A.util.removeClass( component.find("errors"), "slds-hide");
  48. for ( var u in errors[0].fieldErrors) {
  49. component.find("ErrorMessage").set("v.value", errors[0].fieldErrors[u][0].message);
  50. }
  51.  
  52. }
  53. }
  54. });
  55. $A.enqueueAction(saveRecord);
  56. }
  57. })
  58.  
  59. component.set("v.record.Date__c", '2016-1-1' );
  60.  
  61. component.set("v.record.Date__c", '2016-01-01' );
  62.  
  63. rec.Date__c = new Date( rec.Date__c );
  64.  
  65. var rec = component.get( 'v.record' );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement