You need to sign in to do that
Don't have an account?

Lightning component hiding button depending on a field value
Hi,
I am trying to create a Lightning Component to that has a functionality to update a field value(Submit_Go_No_Go_Question__c), and hide the button whenever a field (Go_No_Go_Question__c) is not blank.
Here is my existing code
Apex:
Component:
Controller:
I am trying to create a Lightning Component to that has a functionality to update a field value(Submit_Go_No_Go_Question__c), and hide the button whenever a field (Go_No_Go_Question__c) is not blank.
Here is my existing code
Apex:
public class addGNGQuestion { @AuraEnabled public static void updateChk(String key){ Opportunity acc = [SELECT Id, Name, Submit_Go_No_Go_Question__c, Go_No_Go_Question__c FROM Opportunity WHERE Id=:key]; if(acc.Go_No_Go_Question__c == null){ acc.Submit_Go_No_Go_Question__c = true; } UPDATE acc; } }
Component:
<aura:component controller="addGNGQuestion" implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction" access="global" > <aura:handler event="force:refreshView" action="{!c.isRefreshed}" /> <div class="slds-align_absolute-center" style="height:12rem"> <lightning:button variant="brand" label="Add Go-No Go Question" onclick="{!c.updateCheck}" aura:id="disablebuttonid" /> </div> </aura:component>
Controller:
({ updateCheck : function(component, event, helper) { var rid = component.get("v.recordId"); var action = component.get("c.updateChk"); action.setParams({key : rid}); action.setCallback(this, function(response) { var state = response.getState(); let button = component.find('disablebuttonid'); if(acc.Go_No_Go_Question__c != null){ button.set('v.disabled',true) } if (state === "SUCCESS") { $A.get('e.force:refreshView').fire(); } else if (state === "ERROR") { var errors = response.getError(); if (errors) { if (errors[0] && errors[0].message) { console.log("Error message: " + errors[0].message); } } else { console.log("Unknown Error"); } } }); $A.enqueueAction(action); }, isRefreshed: function(component, event, helper) { location.reload(); }, })Helper:
({ updateCheck11_helper : function(c,e,h) { alert('Success!'); var save_action = c.get("c.updateCheck"); save_action.setParams({ }); $A.enqueueAction(save_action); } })Any help is much appreciated.
Thank you!
ReferenceError: Error in $A.getCallback() [acc is not defined]
Callback failed: apex://addGNGQuestion/ACTION$updateChk
The buttons are disabling after implementing the latest code update. But just a minor problem, the button is getting disabled when Go_No_Go_Question__c does not have a value, and it is enabled when Go_No_Go_Question__c has a value.
I tried modifying the code but still no luck.
Thanks you!
Hi
I have two solutions can you use
1) if(acc.Go_No_Go_Question__c != undefined){
button.set('v.disabled',true)
}
2) <lightning:button variant="brand"
label="Add Go-No Go Question"
onclick="{!c.updateCheck}"
aura:id="disablebuttonid" disabled="{!not(empty(acc.Go_No_Go_Question__c))}"/>
its a not a big task
shall we arrange meeting ?
My Contact number is +917877476049
whatsapp Number +917877476049
Email id HimanshuTakjava@gmail.com