You need to sign in to do that
Don't have an account?
Hema Yejju
I want the lightning button to be disabled after user clicks on 'Payment' button
Hi, I have a lightning aura component and i am using one button in .cmp
<aura:attribute name="showthisButton" type="boolean" default="false"/>
<aura:attribute name="state" type="String" />
<aura:attribute name="response" type= "String" />
<lightning:button variant="brand" label="Yes" class="slds-align_absolute-center"
title="Payment" onclick="{!c.sendEmailNow}"
/>
In Controller:
sendEmailNow: function(component, event, helper){
helper.sendEmailNow(component, event, helper);
In Helper:
sendEmailNow : function(component,event,helper) {
var accountId = component.get("v.accountId");
console.log('in here----'+accountId);
var action = component.get('c.getdetails');//apex class method
action.setParams({ 'AccountId' : accountId });
action.setCallback(this, function(response){
var state = response.getState();
var error= response.getError();
if (state === "SUCCESS") {
component.set('v.showthisButton',false);
} else if (state === "INCOMPLETE") {
alert ("Failed ");
}else if (state === "ERROR") {
var errors = response.getError();
if (!errors) {
errors = [{"message" : "Unknown Error Occured"}];
}
alert ("Error occured"+errors);
}
});
$A.enqueueAction(action);
}
<aura:attribute name="showthisButton" type="boolean" default="false"/>
<aura:attribute name="state" type="String" />
<aura:attribute name="response" type= "String" />
<lightning:button variant="brand" label="Yes" class="slds-align_absolute-center"
title="Payment" onclick="{!c.sendEmailNow}"
/>
In Controller:
sendEmailNow: function(component, event, helper){
helper.sendEmailNow(component, event, helper);
In Helper:
sendEmailNow : function(component,event,helper) {
var accountId = component.get("v.accountId");
console.log('in here----'+accountId);
var action = component.get('c.getdetails');//apex class method
action.setParams({ 'AccountId' : accountId });
action.setCallback(this, function(response){
var state = response.getState();
var error= response.getError();
if (state === "SUCCESS") {
component.set('v.showthisButton',false);
} else if (state === "INCOMPLETE") {
alert ("Failed ");
}else if (state === "ERROR") {
var errors = response.getError();
if (!errors) {
errors = [{"message" : "Unknown Error Occured"}];
}
alert ("Error occured"+errors);
}
});
$A.enqueueAction(action);
}
Please try the below :
HTML:
Add the aura:id in button
Helper JS:
use component.find("PaymentBtn").set("v.disabled", true);
Thanks,
Maharajan.C
Tried your code ...After clicking on that button it was not getting disabled .after few seconds like 5 to 10 middle its getting disabled ..but i need immediate action on the button click l..any ther alternative please???
Controller:
Then put disable logic it in the controller method ... Your apex class is taking time so there is few seconds like 5 to 10... So moved the button disable in controller... Also in failure or Incomplete if you want you can undisable the button...
Thanks,
Maharajan.C