Created
December 30, 2017 17:37
-
-
Save yasarshaikh/8edea8850bced036bec925a1d6f6db47 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<aura:component implements="flexipage:availableForAllPageTypes" access="global" > | |
<aura:attribute name="boat" type="Boat__c" access="public"/> | |
<!-- <aura:attribute name="BoatReview" type="Object" access="private"/> --> | |
<aura:attribute name="boatReview" type="BoatReview__c" access="private"/> | |
<aura:attribute name="newBoatReview" type="Object" /> | |
<aura:attribute name="recordError" type="String" access="private"/> | |
<aura:registerEvent name="BoatReviewAdded" type="c:BoatReviewAdded" /> | |
<aura:handler name="init" value="{!this}" action="{!c.doInit}"/> | |
<force:recordData aura:id="service" | |
layoutType="FULL" | |
fields="Id, Name, Comment__c, Boat__c, Rating__c" | |
targetFields="{!v.boatReview}" | |
targetError="{!v.recordError}" | |
recordUpdated="{! c.onRecordUpdated }" /> | |
<!-- Display Lightning Data Service errors --> | |
<aura:if isTrue="{!not(empty(v.recordError))}"> | |
<div class="recordError"> | |
<ui:message title="Error" severity="error" closable="true"> | |
{!v.recordError} | |
</ui:message> | |
</div> | |
</aura:if> | |
<!-- Display the new contact form --> | |
<div class="slds-form slds-form_stacked"> | |
<lightning:input aura:id="title" name="title" label="Title" | |
value="{! v.boatReview.Name }" required="true"/> | |
<lightning:inputRichText aura:id="Comment" value="{! v.boatReview.Comment__c }" disabledCategories="FORMAT_FONT"/> | |
<lightning:button label="Submit" onclick="{!c.onSave }" | |
iconName="utility:save" /> | |
</div> | |
</aura:component> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
({ | |
doInit : function(component, event, helper) { | |
helper.onInit(component, event, helper); | |
}, | |
onSave : function(component, event, helper) { | |
component.find("service").saveRecord($A.getCallback(function (saveResult){ | |
if (saveResult.state == 'ERROR') | |
{ | |
console.log('Error saving review record: ' + component.get('v.recordError')); | |
} | |
else { | |
var toastEvent = $A.get('e.force:showToast'); | |
if (toastEvent) { | |
toastEvent.setParams({ | |
title: 'Success!', | |
message: 'Your review has been saved successfully' | |
}); | |
toastEvent.fire(); | |
} else { | |
alert (message); | |
} | |
helper.onInit(component, event, helper); | |
component.getEvent('BoatReviewAdded').fire(); | |
} | |
})); | |
}, | |
onRecordUpdated: function(component, event, helper){ | |
} | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
({ | |
onInit : function(component, event, helper) { | |
var recordTypeId = null; | |
var skipCache = false; | |
var boatid = component.get('v.boat.Id'); | |
component.find("service").getNewRecord( | |
'BoatReview__c', | |
recordTypeId, | |
skipCache, | |
$A.getCallback(function() { | |
var review = component.get('v.boatReview'); | |
var error = component.get('v.recordError'); | |
if (error || !review) { | |
console.log('Error initalizing review template: ' + error); | |
} else { | |
review.Boat__c = component.get('v.boat').Id; | |
} | |
}) | |
); | |
}, | |
alertSuccess: function(message) { | |
var toastEvent = $A.get('e.force:showToast'); | |
if (toastEvent) { | |
toastEvent.setParams({ | |
title: 'Success!', | |
message: message | |
}); | |
toastEvent.fire(); | |
} else { | |
alert (message); | |
} | |
} | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<aura:component implements="flexipage:availableForAllPageTypes" access="global"> | |
<aura:attribute name="boat" type="Boat__c" /> | |
<aura:attribute name="id" type="Id" /> | |
<aura:attribute access="private" name="selectedTabId" type="String"/> | |
<aura:handler event="c:BoatSelected" action="{! c.onBoatSelected }"/> | |
<aura:handler event="c:BoatReviewAdded" name="BoatReviewAdded" action="{! c.onBoatReviewAdded }" phase="capture"/> | |
<force:recordData aura:id="service" | |
recordId="{!v.id}" | |
layoutType="FULL" | |
fields="Id, Name, Description__c, Price__c, Length__c, Contact__r.Name, Contact__r.Email, Contact__r.HomePhone, BoatType__r.Name, Picture__c" | |
targetFields="{!v.boat}" | |
recordUpdated="{! c.onRecordUpdated }" | |
/> | |
<aura:if isTrue="{! v.boat != undefined }"> | |
<lightning:tabset aura:id="boatTabSet" selectedTabId="{!v.selectedTabId}"> | |
<lightning:tab label="Details" id="tabDetails"> | |
<c:BoatDetail boat="{! v.boat }" /> | |
</lightning:tab> | |
<lightning:tab label="Reviews" id="Reviews"> | |
</lightning:tab> | |
<lightning:tab label="Add Review" id="tabAddReview"> | |
<c:AddBoatReview boat="{! v.boat }" /> | |
</lightning:tab> | |
</lightning:tabset> | |
</aura:if> | |
</aura:component> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
({ | |
onBoatSelected : function(component, event, helper) { | |
var boat = event.getParam('boat'); | |
component.set("v.boat" , boat); | |
component.set("v.id" , component.get("v.boat.Id")) ; | |
component.find('service').reloadRecord(); | |
}, | |
onRecordUpdated : function(component, event, helper) { | |
}, | |
onBoatReviewAdded : function(component, event, helper) { | |
component.set('v.selectedTabId', 'Reviews'); | |
} | |
}) |
Hi thanks for the sharing, your onSave(component, event, helper)
method in AddBoatReview.cmp
helped me successfully initialize BoatReview record. I was stuck in this problem for hours.
However, I'm having a hard time understanding why using component.find("service").saveRecord($A.getCallback(function (saveResult){}))
, instead of component.find("service").saveRecord(function (saveResult){})
. And this seems like to be why my code didn't work.
Many thanks in advance :)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
onBoatReviewAdded : function(component, event, helper) { component.set('v.selectedTabId', 'boatreviewtab'); }