How to show and hide the form in Salesforce Lightning
Component1
----------
<aura:component implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes" access="global"
controller="AccController">
<aura:attribute name="acc" type="Account" default="{'sobjectType':'Account',
'Name':'',
'Email__c':'',
'Site':'',
'AccountNumber':''}"/>
<div align="center">
<lightning:button label="Cancel" onclick="{!c.Cancel}" />
<lightning:button label="view" onclick="{!c.View}" />
</div>
<div align="center">
<div class="input-group col-sm-5" id="test" style="width:120px" >
<lightning:input type="text" label="Name" placeholder="Name" value="{!v.acc.Name}" required="true"/>
<lightning:input type="Email" label="Email" placeholder="Email" value="{!v.acc.Email__c}" />
<lightning:input type="text" label="Site" placeholder="Site" value="{!v.acc.Site}"/>
<lightning:input type="number" label="Number" placeholder="Number" value="{!v.acc.AccountNumber}" />
<lightning:button label="Save" onclick="{!c.save}"/> </div>
</div>
</aura:component>
controller
----------
({
View : function(component, event, helper){
document.getElementById('test').style.display = 'block';
},
Cancel : function(component, event, helper){
document.getElementById('test').style.display = 'none';
},
save : function(component, event, helper) {
var action = component.get("c.creatAccountRecord");
action.setParams({"acc":component.get("v.acc")});
action.setCallback(this,function(result){
component.set("v.isShow",false);
console.log('Checking the status');
alert('Data saved');
});
$A.enqueueAction(action);
},
})
Apex class
----------
public class AccController {
@auraenabled
public static Id creatAccountRecord(Account acc){
upsert acc;
return acc.id;
}
}
Lightning ApplicationException
-------------------------------
<aura:application extends="force:slds">
Component1
</aura:application>
----------
<aura:component implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes" access="global"
controller="AccController">
<aura:attribute name="acc" type="Account" default="{'sobjectType':'Account',
'Name':'',
'Email__c':'',
'Site':'',
'AccountNumber':''}"/>
<div align="center">
<lightning:button label="Cancel" onclick="{!c.Cancel}" />
<lightning:button label="view" onclick="{!c.View}" />
</div>
<div align="center">
<div class="input-group col-sm-5" id="test" style="width:120px" >
<lightning:input type="text" label="Name" placeholder="Name" value="{!v.acc.Name}" required="true"/>
<lightning:input type="Email" label="Email" placeholder="Email" value="{!v.acc.Email__c}" />
<lightning:input type="text" label="Site" placeholder="Site" value="{!v.acc.Site}"/>
<lightning:input type="number" label="Number" placeholder="Number" value="{!v.acc.AccountNumber}" />
<lightning:button label="Save" onclick="{!c.save}"/> </div>
</div>
</aura:component>
controller
----------
({
View : function(component, event, helper){
document.getElementById('test').style.display = 'block';
},
Cancel : function(component, event, helper){
document.getElementById('test').style.display = 'none';
},
save : function(component, event, helper) {
var action = component.get("c.creatAccountRecord");
action.setParams({"acc":component.get("v.acc")});
action.setCallback(this,function(result){
component.set("v.isShow",false);
console.log('Checking the status');
alert('Data saved');
});
$A.enqueueAction(action);
},
})
Apex class
----------
public class AccController {
@auraenabled
public static Id creatAccountRecord(Account acc){
upsert acc;
return acc.id;
}
}
Lightning ApplicationException
-------------------------------
<aura:application extends="force:slds">
Component1
</aura:application>
Great Information you have shared, Check it once salesforce Online Training
ReplyDelete