+ Start a Discussion
Viru D.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);
    },
Best Answer chosen by Viru D.
Ashwin Kumar SrinivasanAshwin Kumar Srinivasan
Hi,

I think the issue is in where you set the 
component.set("V.isError", showerror2);
change to
component.set("v.isError", showerror2);
accross the component everywhere it is used as V.isError change that to v.isError.

Thanks

All Answers

Ashwin Kumar SrinivasanAshwin Kumar Srinivasan
Hi,

I think the issue is in where you set the 
component.set("V.isError", showerror2);
change to
component.set("v.isError", showerror2);
accross the component everywhere it is used as V.isError change that to v.isError.

Thanks
This was selected as the best answer
Viru D.Viru D.
Thanks Ashwin and Alaian,

It worked.