Skip to content

Instantly share code, notes, and snippets.

@iamsonal
iamsonal / quickAdd.cmp
Last active June 27, 2017 13:38
quickAdd.cmp
<!--quickAdd.cmp-->
<aura:component implements="force:lightningQuickAction" >
<lightning:input type="number" name="myNumber" aura:id="num1" label="Number 1"/>
<lightning:input type="number" name="myNumber" aura:id="num2" label="Number 2"/>
<br/>
<lightning:button label="Add" onclick="{!c.clickAdd}"/>
</aura:component>
@iamsonal
iamsonal / quickAddController.js
Created June 27, 2017 13:39
quickAddController.js
/*quickAddController.js*/
({
clickAdd: function(component, event, helper) {
// Get the values from the form
var n1 = component.find("num1").get("v.value");
var n2 = component.find("num2").get("v.value");
// Display the total in a "toast" status message
var resultsToast = $A.get("e.force:showToast");
resultsToast.setParams({
"title": "Quick Add: " + n1 + " + " + n2,
<aura:component >
<aura:attribute name="index" type="Integer" default="1" />
<aura:attribute name="buttonLabel" type="String" />
<div style="margin-top=20px;text-align:center;width=100%">
<lightning:button variant="brand" label="Create Component" onclick="{! c.createComponent }" />
<lightning:button variant="destructive" label="Remove Component" onclick="{! c.removeComponent }" />
</div>
<br/><br/>
<div style="border:10px ridge red;height:50%;width:100%">
@iamsonal
iamsonal / DynamicComponentController.js
Created June 27, 2017 13:51
DynamicComponentController.js
({
createComponent : function(component, event, helper) {
var index = component.get("v.index");
$A.createComponent(
"ui:Button",
{
"label":"Button " + index,
"press":component.getReference("c.show")
},
function(button) {
@iamsonal
iamsonal / compEvent.evt
Last active June 28, 2017 08:34
compEvent and appEvent events
<!--c:compEvent-->
<aura:event type="COMPONENT">
<!-- pass context of where the event was fired to the handler. -->
<aura:attribute name="context" type="String"/>
</aura:event>
<!--c:appEvent-->
<aura:event type="APPLICATION">
<!--c:eventsNotifier-->
<aura:component>
<aura:attribute name="parentName" type="String"/>
<aura:registerEvent name="componentEventFired" type="c:compEvent"/>
<aura:registerEvent name="appEvent" type="c:appEvent"/>
<div>
<h3>This is {!v.parentName}'s eventsNotifier.cmp instance</h3>
<p>
<lightning:button label="Click here to fire a component event" onclick="{!c.fireComponentEvent}" />
</p>
<!--c:eventsHandler-->
<aura:component>
<aura:attribute name="name" type="String"/>
<aura:attribute name="mostRecentEvent" type="String" default="Most recent event handled:"/>
<aura:attribute name="numComponentEventsHandled" type="Integer" default="0"/>
<aura:attribute name="numApplicationEventsHandled" type="Integer" default="0"/>
<aura:handler event="c:appEvent" action="{!c.handleApplicationEventFired}"/>
<aura:handler name="componentEventFired" event="c:compEvent" action="{!c.handleComponentEventFired}"/>
<aura:application extends="force:slds">
<c:eventsHandler name="eventsHandler1"/>
<c:eventsHandler name="eventsHandler2"/>
</aura:application>
<aura:application controller="echoController" extends="force:slds">
<aura:attribute name="echoes" type="String[]"/>
<div class="slds-grid slds-wrap container">
<div class="slds-size--3-of-12">Foreground Action</div>
<div class="slds-size--3-of-12">Background Action</div>
<div class="slds-size--3-of-12">Storable Action</div>
<div class="slds-size--3-of-12">Abortable Action</div>
<div class="slds-size--3-of-12">
({
doForeground: function(cmp, event, helper) {
helper.echo(cmp, 'Foreground #1');
helper.echo(cmp, 'Foreground #2');
},
doBackground: function(cmp, event, helper) {
helper.echo(cmp, 'Background #1', function(action) {
action.setBackground();
});