+ Start a Discussion
suji srinivasansuji srinivasan 

how to disable input calender field?

hi, how to enable input calendar field for picklist option1-Reengagement
and disable the same input calendar field for picklist option 2-Inadeqautedata  in aura.

<lightning:select aura:id="industryPicklist" value="{!v.lead.Industry}" onchange="{!c.handleOnChange}" name="industryPicklist" label="Industry" required="true">
                    <option value="">--None--</option>
                    <option value="1">Re engagement</option>
                   
                    <option value="2">Inadequate Data</option>
                   <lightning:input type="date" name="input1" label="Re engagement" /> 
Thanks in advance
Best Answer chosen by suji srinivasan
suji srinivasansuji srinivasan
hi , i resolved it by refering this 
https://developer.salesforce.com/forums/?id=9062I000000Qv1oQAC
Thank you for your support.

All Answers

PriyaPriya (Salesforce Developers) 
Hi Suji,

Can you please make use of aura if like below.https://salesforce.stackexchange.com/questions/240059/how-to-display-hide-fields-in-lightning-component-using-javascript

Hope this is helpful..please mark this as best answer!!
Regards,
Ranjan
suji srinivasansuji srinivasan
Hi, this is my code. I need to enable input calendar field for picklist option1-Reengagement
and disable the same input calendar field for picklist option 2-Inadeqautedata  in aura. 

component:
<aura:component controller="DynamicPicklist" implements="flexipage:availableForAllPageTypes,force:appHostable">
     
    
    <aura:attribute name="fieldMap" type="Map"/>
 <aura:attribute name="lead" type="Lead" default="{'sobjectType':'Lead', 
                                                       'LastName': '',
                                                       'Company': '',
                                                       'Email': '',
                                                       'Phone': '', 
                                                       'Industry': ''}"/>
     
    <!--Declare Handler-->
    <aura:handler name="init" value="{!this}" action="{!c.doInit}"/>  
     
    <!--Component Start-->
    <div class="slds-m-around--xx-large">
        <div class="container-fluid">
            <div class="form-group">
                <lightning:input name="Name" type="text" label="Lead Name" value="{!v.lead.LastName}" />
            </div>
            <div class="form-group">
                <lightning:input name="Company" type="text" label="Company" value="{!v.lead.Company}" />
            </div>
            <div class="form-group">
                <lightning:input name="Email" type="email" label="Email" value="{!v.lead.Email}" />
            </div>
            <div class="form-group">
                <lightning:input name="Phone" type="phone" label="Phone" value="{!v.lead.Phone}" />
            </div>
            <div class="form-group">
                <lightning:select aura:id="industryPicklist" value="{!v.lead.Industry}" onchange="{!c.handleOnChange}" name="industryPicklist" label="Industry" required="true">
                    <option value="">--None--</option>
                    <option value="1">Re engagement</option>
                   
                    <option value="2">Inadequate Data</option>
                   
                   <!-- <aura:iteration items="{!v.fieldMap}" var="i" indexVar="key">
                        <option text="{!i.value}" value="{!i.key}" selected="{!i.key==v.lead.Industry}" />
                    </aura:iteration>-->
                </lightning:select>
                </div>
            <div class="row">
      
                <aura:if isTrue="{!v.lead.Industry}" ><option value="1">Re engagement</option>>
                <lightning:input type="date" name="input1" label="Re engagement" /> 
                      </aura:if>
                
            </div>
        </div>
        <br/>
        <lightning:button variant="brand" label="Submit" onclick="{!c.LeadSave}" />              
    </div>
   </aura:component>
controller:
({
    
    doInit: function(component, event, helper) {        
        helper.getPicklistValues(component, event);
    },
     
    
    LeadSave : function(component, event, helper) {
        helper.saveLead(component, event);
    },
     
    //handle Industry Picklist Selection
    handleOnChange : function(component, event, helper) {
        var industry = component.get("v.lead.Industry",true);
        alert(industry);
    }

})

helper:
({
    
    getPicklistValues: function(component, event) {
        var action = component.get("c.getIndustryFieldValue");
        action.setCallback(this, function(response) {
            var state = response.getState();
            if (state === "SUCCESS") {
                var result = response.getReturnValue();
                var fieldMap = [];
                for(var key in result){
                    fieldMap.push({key: key, value: result[key]});
                }
                component.set("v.fieldMap", fieldMap);
            }
        });
        $A.enqueueAction(action);
    },
     
    
    saveLead : function(component, event) {
        var lead = component.get("v.lead");
        var action = component.get("c.createLead");
        action.setParams({
            leadobj : lead
        });
        action.setCallback(this,function(response){
            var state = response.getState();
            if(state === "SUCCESS"){
                alert('Record Created Successfully!!');
            } else if(state === "ERROR"){
                var errors = action.getError();
                if (errors) {
                    if (errors[0] && errors[0].message) {
                        alert(errors[0].message);
                    }
                }
            }
        });       
        $A.enqueueAction(action);
    }
})

Apex:
public class DynamicPicklist {
        @AuraEnabled 
    Public static void createLead(Lead leadobj){
        try{
            
            insert leadobj; 
             
        }catch(Exception e){
            System.debug(e.getMessage());
            System.debug(e.getLineNumber());
        }
        
    }
     
    @AuraEnabled 
    public static Map<String, String> getIndustryFieldValue(){
        Map<String, String> options = new Map<String, String>();
        
        Schema.DescribeFieldResult fieldResult = Lead.Industry.getDescribe();
        
        List<Schema.PicklistEntry> pValues = fieldResult.getPicklistValues();
        for (Schema.PicklistEntry p: pValues) {
            
            options.put(p.getValue(), p.getLabel());
        }
        return options;
    }
}
Thanks in advance
Vladyslav LazurchenkoVladyslav Lazurchenko
Hello, thanks for there solutions. Had the same problem

Vladyslav
Find me at https://www.chess.com/member/lazurchenko
jhon marriejhon marrie

Thank you for sharing.
I believe you must first comprehend it, for which you may go to (https://www.processfusion.com/en) in the hopes of resolving the problem.

mukesh guptamukesh gupta
Hi Suji,

Use below code:-
 
<aura:attribute name = 'flag' type = "boolen" default = "false"/>
 <div class="slds-m-around--xx-large">
        <div class="container-fluid">
            <div class="form-group">
                <lightning:input name="Name" type="text" label="Lead Name" value="{!v.lead.LastName}" />
            </div>
            <div class="form-group">
                <lightning:input name="Company" type="text" label="Company" value="{!v.lead.Company}" />
            </div>
            <div class="form-group">
                <lightning:input name="Email" type="email" label="Email" value="{!v.lead.Email}" />
            </div>
            <div class="form-group">
                <lightning:input name="Phone" type="phone" label="Phone" value="{!v.lead.Phone}" />
            </div>
            <div class="form-group">
                <lightning:select aura:id="industryPicklist" value="{!v.lead.Industry}" onchange="{!c.handleOnChange}" name="industryPicklist" label="Industry" required="true">
                    <option value="">--None--</option>
                    <option value="1">Re engagement</option>
                   
                    <option value="2">Inadequate Data</option>
                   
                   <!-- <aura:iteration items="{!v.fieldMap}" var="i" indexVar="key">
                        <option text="{!i.value}" value="{!i.key}" selected="{!i.key==v.lead.Industry}" />
                    </aura:iteration>-->
                </lightning:select>
                </div>
            <div class="row">
      
                <lightning:input type="date" name="input1" label="Re engagement" disabled = "{!flag}" /> 
                
            </div>
        </div>
        <br/>
        <lightning:button variant="brand" label="Submit" onclick="{!c.LeadSave}" />              
    </div>
   </aura:component>
 
({
    
    doInit: function(component, event, helper) {        
        helper.getPicklistValues(component, event);
    },
     
    
    LeadSave : function(component, event, helper) {
        helper.saveLead(component, event);
    },
     
    //handle Industry Picklist Selection
    handleOnChange : function(component, event, helper) {
	   if(event.target.value == 'Reengagement'){
	    component.set("v.flag", "true")
	   
	   }else{
	   component.set("v.flag", "false")
	   }
        
    }

})
if you need any assistanse, Please let me know!!

Kindly mark my solution as the best answer if it helps you.

Thanks
Mukesh 

 
suji srinivasansuji srinivasan
Hi Mukesh, In UI according to flag boolean it displays the value . i want to restrict it for picklist value 2. calender should be visible only for picklist value 1(Re engagement). I dont know what i missed out. could you help me?. Thanks in advance

component
<aura:component controller="DynamicPicklist" implements="flexipage:availableForAllPageTypes,force:appHostable">

    <aura:attribute name="flag" type="boolean" default="false" />
    <aura:attribute name="fieldMap" type="Map"/>
    <aura:attribute name="lead" type="Lead" default="{'sobjectType':'Lead', 
                                                       'LastName': '',
                                                       'Company': '',
                                                       'Email': '',
                                                       'Phone': '', 
                                                       'Industry': ''}"/>
    
 <div class="slds-m-around--xx-large">
        <div class="container-fluid">
            <div class="form-group">
                <lightning:input name="Name" type="text" label="Lead Name" value="{!v.lead.LastName}" />
            </div>
            <div class="form-group">
                <lightning:input name="Company" type="text" label="Company" value="{!v.lead.Company}" />
            </div>
            <div class="form-group">
                <lightning:input name="Email" type="email" label="Email" value="{!v.lead.Email}" />
            </div>
            <div class="form-group">
                <lightning:input name="Phone" type="phone" label="Phone" value="{!v.lead.Phone}" />
            </div>
            <div class="form-group">
                <lightning:select aura:id="industryPicklist" value="{!v.lead.Industry}" onchange="{!c.handleOnChange}" name="Industry" label="Industry" required="true">
                    <option value="">--None--</option>
                    <option value="1">Re engagement</option>
                   
                    <option value="2">Inadequate Data</option>
             </lightning:select>
                </div>
          <aura:if isTrue="{!v.flag}">
             <lightning:input type="date" name="input1" label="Enter a date" value="{! v.date }" />
            </aura:if>
       </div>
        <br/>
        <lightning:button variant="brand" label="Submit" onclick="{!c.LeadSave}" />              
    </div>
   </aura:component>
controller:
({
    
    doInit: function(component, event, helper) {        
        helper.getPicklistValues(component, event);
    },
     
    
    LeadSave : function(component, event, helper) {
        helper.saveLead(component, event);
    },
     
    //handle Industry Picklist Selection
    handleOnChange : function(component, event, helper) {
      var sel = component.find("industryPicklist").get("v.value");
       
         if (sel=="Re engagement") {     
              component.set("v.flag",true);
         }
        else if(sel=="Inadequate Data"){
            component.set("v.flag",false);
         }
        
    }

})
suji srinivasansuji srinivasan
hi , i resolved it by refering this 
https://developer.salesforce.com/forums/?id=9062I000000Qv1oQAC
Thank you for your support.
This was selected as the best answer