Skip to content

Instantly share code, notes, and snippets.

View choudharymanish8585's full-sized avatar
💭
Never Settle

Manish Choudhari choudharymanish8585

💭
Never Settle
View GitHub Profile
({
/*
* This method will call the server side action and will execute callback method
* it will also show error if generated any
* @param component (required) - Calling component
* @param method (required) - Server side methos name
* @param callback (required) - Callback function to be executed on server response
* @param params (optional) - parameter values to pass to server
* @param setStorable(optional) - if true, action response will be stored in cache
* */
({
getCarType : function(component, helper) {
var action = component.get("c.getCarTypes");
action.setCallback(this, function(data) {
component.set("v.carTypes", data.getReturnValue());
});
$A.enqueueAction(action);
},
})
({
doInit : function(component, event, helper) {
var createBoatRecord = $A.get("e.force:createRecord");
if(createBoatRecord){ //check if this event is available or not
component.set("v.showNew", true);
} else{
component.set("v.showNew", false);
}
},
<aura:component controller="CarTypeSearch"
implements="force:appHostable,flexipage:availableForRecordHome,force:hasRecordId">
<!-- Attribute to controle visibility of New button -->
<aura:attribute name="showNew" type="boolean" />
<aura:attribute name="carTypes" type="Car_Type__c[]"/>
<aura:handler name="init" action="{!c.doInit}" value="{!this}"/>
<!-- This event will be fired when user will click on
<aura:component controller="CarTypeSearch"
implements="force:appHostable,flexipage:availableForRecordHome,force:hasRecordId">
<!-- Attribute to controle visibility of New button -->
<aura:attribute name="showNew" type="boolean" />
<aura:attribute name="carTypes" type="Car_Type__c[]"/>
<aura:handler name="init" action="{!c.doInit}" value="{!this}"/>
<!-- This event will be fired when user will click on
<aura:application extends="force:slds" >
<c:CarSearchForm />
</aura:application>
<aura:component implements="force:appHostable,flexipage:availableForRecordHome,force:hasRecordId">
<lightning:layout horizontalAlign="center">
<lightning:layoutItem>
<lightning:select name='selectItem' aura:id="carType" label='All Types'
variant="label-hidden" value="">
<option value="" text="All Types" />
<option value="" text="Sports Car" />
<option value="" text="Luxury Car" />
</lightning:select>
({
saveAccount : function(component) {
/************************
* I am writing dummy code to clear input boxes here,
* but in real you need to save all unsaved changes here
***********************/
component.find("name").set("v.value", "");
component.find("phone").set("v.value", "");
}
})
({
/**
* in this function we will set unsaved changes
* as the user is changing data which should be saved
* before page close
* */
handleDataChange: function(component, event, helper) {
//get instance of unsavedChanges component
var unsavedData = component.find("unsavedData");
//set unsaved changes which will notify the user about saving the record on page close
<aura:component implements="flexipage:availableForRecordHome" access="global" >
<!--intantiating unsaved changed component -->
<lightning:unsavedChanges aura:id="unsavedData"
onsave="{!c.saveData}"
ondiscard="{!c.discardData}"/>
<lightning:card title="Create Account">
<!-- Handle name change, make unsaved changes in this action as user has typed some value-->
<lightning:input name="Name" aura:id="name" label="Enter name" onchange="{!c.handleDataChange}"/>