You need to sign in to do that
Don't have an account?
Viru D.
Set Boolean value from controller is not working
Trying to set value of boolean variable isError to true when required to display error message. But not working !!
Let me know if any solution or error in code..
Code snipet :-
<aura:component controller="Sample_Req_Line_Comp_CLS" implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction" access="global" >
<aura:attribute name="recordId" type="String" />
<aura:attribute name="options" type="List" />
<aura:attribute name="options2" type="List" />
<aura:attribute name="SelectedFamily" type="String" default="Red"/>
<aura:attribute name="selectedProduct" type="String" default="Red"/>
<aura:attribute name="InventoryRecord" type="Sample_Inventory__c" default="{sobjectType: 'Sample_Inventory__c',name : 'akshfdkjdsahf'}" />
<aura:handler name="init" value="{!this}" action="{!c.doInit}" />
<aura:attribute name="Request_Qty" type="Integer" />
<aura:attribute name="recordError" type="String" access="private"/>
<aura:attribute name="isError" type="boolean" default="false"/>
<div class="slds-m-left_x-large" >
<lightning:layout class="slds-page-header slds-page-header--object-home">
<lightning:layoutItem >
<lightning:icon iconName="standard:orders" alternativeText="My Expenses"/>
</lightning:layoutItem>
<lightning:layoutItem padding="horizontal-small">
<div class="page-section page-header">
<h1 class="slds-text-heading--label">Sample Request Line</h1>
<h2 class="slds-text-heading--medium">Order Samples</h2>
</div>
</lightning:layoutItem>
</lightning:layout>
checking here ==> {!v.isError}
<aura:if isTrue="{!v.isError}">
<ui:message title="Error" severity="error" closable="true" class="slds-form-element slds-size_1-of-12 slds-m-bottom_medium">
<b> {!v.recordError} </b>
</ui:message>
</aura:if>
Controller : -
SaveData_Ctrl: function(component, event, helper, ReqQty,selectedProduct,SampleReq_id) {
var action = component.get("c.SaveData2");
action.setParams({
"Requested_Qty": ReqQty,
"selectedProduct": selectedProduct,
"SampleReq_id": SampleReq_id
});
action.setCallback(this, function(response) {
if (response.getState() === "SUCCESS") {
var showerror = false;
component.set("V.isError", showerror);
component.set("v.InventoryRecord", response.getReturnValue());
console.log('==Success isError==' + component.get("V.isError"));
}
else{
var errors = action.getError();
var showerror2 = true;
component.set("V.isError", showerror2);
component.set("v.recordError", errors[0].message);
console.log('==checking isError==' + component.get("V.isError"));
}
});
$A.enqueueAction(action);
},
Let me know if any solution or error in code..
Code snipet :-
<aura:component controller="Sample_Req_Line_Comp_CLS" implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction" access="global" >
<aura:attribute name="recordId" type="String" />
<aura:attribute name="options" type="List" />
<aura:attribute name="options2" type="List" />
<aura:attribute name="SelectedFamily" type="String" default="Red"/>
<aura:attribute name="selectedProduct" type="String" default="Red"/>
<aura:attribute name="InventoryRecord" type="Sample_Inventory__c" default="{sobjectType: 'Sample_Inventory__c',name : 'akshfdkjdsahf'}" />
<aura:handler name="init" value="{!this}" action="{!c.doInit}" />
<aura:attribute name="Request_Qty" type="Integer" />
<aura:attribute name="recordError" type="String" access="private"/>
<aura:attribute name="isError" type="boolean" default="false"/>
<div class="slds-m-left_x-large" >
<lightning:layout class="slds-page-header slds-page-header--object-home">
<lightning:layoutItem >
<lightning:icon iconName="standard:orders" alternativeText="My Expenses"/>
</lightning:layoutItem>
<lightning:layoutItem padding="horizontal-small">
<div class="page-section page-header">
<h1 class="slds-text-heading--label">Sample Request Line</h1>
<h2 class="slds-text-heading--medium">Order Samples</h2>
</div>
</lightning:layoutItem>
</lightning:layout>
checking here ==> {!v.isError}
<aura:if isTrue="{!v.isError}">
<ui:message title="Error" severity="error" closable="true" class="slds-form-element slds-size_1-of-12 slds-m-bottom_medium">
<b> {!v.recordError} </b>
</ui:message>
</aura:if>
Controller : -
SaveData_Ctrl: function(component, event, helper, ReqQty,selectedProduct,SampleReq_id) {
var action = component.get("c.SaveData2");
action.setParams({
"Requested_Qty": ReqQty,
"selectedProduct": selectedProduct,
"SampleReq_id": SampleReq_id
});
action.setCallback(this, function(response) {
if (response.getState() === "SUCCESS") {
var showerror = false;
component.set("V.isError", showerror);
component.set("v.InventoryRecord", response.getReturnValue());
console.log('==Success isError==' + component.get("V.isError"));
}
else{
var errors = action.getError();
var showerror2 = true;
component.set("V.isError", showerror2);
component.set("v.recordError", errors[0].message);
console.log('==checking isError==' + component.get("V.isError"));
}
});
$A.enqueueAction(action);
},
I think the issue is in where you set the change to accross the component everywhere it is used as V.isError change that to v.isError.
Thanks
All Answers
<aura:attribute name="isError" type="Boolean" default="false"/>
https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/aura_compref_aura_if.htm
https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/ref_attr_types_basic.htm
I think the issue is in where you set the change to accross the component everywhere it is used as V.isError change that to v.isError.
Thanks
It worked.