function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
komal pulani 2komal pulani 2 

Requirement is to change the variable value inside aura:if

Hi, I have a requirement where i want to change the value of attribute insode the aura:if.
I want to set the value of disableActivityDate to True if  BranchValue!=null .Here is my code:
 <aura:attribute name="disableActivityDate" type="String" default="true"/>
 <aura:If isTrue="{!v.BranchValue!=null}">                              
   <lightning:inputField fieldName="Activity_Date__c" aura:id="dateField" onchange="{!c.resetActivityTimeSelection}" disabled="{!v.disableActivityDate}"/>   
                       </lightning:layoutItem>
                      </aura:If>
Ajay K DubediAjay K Dubedi
Hi komal,
Please try below code and let me know if this works for you. If still need modifications do let me know.

Component :
<aura:component >
<aura:attribute name="disableActivityDate" type="boolean" default="false"/>
    <aura:attribute name="BranchValue" type="String" />
       <aura:handler name="init" value="{!this}" action="{!c.doInit}"/>
 <aura:If isTrue="{!v.BranchValue!=null}">      
   <lightning:input fieldName="FirstName" aura:id="dateField" onchange="{!c.resetActivityTimeSelection}" disabled="{!v.disableActivityDate}"/>   
 </aura:If>
</aura:component>

Controller:
({
    doInit:function (component, event, helper) {
        component.set("v.BranchValue",'IMS');
        if(component.get("v.BranchValue") != null){
        component.set("v.disableActivityDate",true);
            
        }
        console.log(component.get("v.BranchValue"));
    },
})

I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks,
Ajay Dubedi
 
Richard MarRichard Mar
Hi Komal,
 
Try this.

Component:
<aura:component >
    <aura:attribute name="disableActivityDate" type="Boolean" default="true"/>
    <aura:attribute name="BranchValue" type="String" default=""/>
    <aura:handler name="change" value="{!v.BranchValue}" action="{c.onBranchValueChange}" />
    
    <aura:If isTrue="{!v.BranchValue!=null}">                              
        <lightning:inputField fieldName="Activity_Date__c" aura:id="dateField" onchange="{!c.resetActivityTimeSelection}" disabled="{!v.disableActivityDate}" />   
    </aura:If>
</aura:component>

Controller:
onBranchValueChange : function(cmp, event, helper) {
        var branchValue = cmp.set("v.BranchValue");
        if (branchValue ! null)
        	cmp.set("v.disableActivityDate", true);
    }

 
Deepali KulshresthaDeepali Kulshrestha
Hi Komal,
I went through the code of yours and found that you have taken the type of the attribute as a string and you are trying to use it as boolean which is causing the problem. Please change your type from "String" to "Boolean" as the disabled attribute of the input field works only with the boolean value.
Please change your attribute :
 <aura:attribute name="disableActivityDate" type="String" default="true"/>
to:
<aura:attribute name="disableActivityDate" type="Boolean" default="true"/>

I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.

Thanks and Regards,
Deepali Kulshrestha.