0

enter image description here When I click on Edit Button

enter image description here When I have changed value of "Case Type" picklist, Request Detail section is to appear on change of picklist value

I want to show this section on load of this edit page. I am using following code.

<aura:handler name="init" action="{!c.doInit}" value="{!this}"/>

 <lightning:inputField fieldName="Type" aura:id ="caseTypeId" onchange="{!c.caseTypeChange}"/> 

<aura:if isTrue="{!v.caseTypeValue =='Requests'}"> 
                     <br/>
                      <h3 class="slds-section-title--divider">Request Details</h3>
                      <div class="slds-grid">
                        <div class="slds-col">
                          <span>
                               <lightning:inputField fieldName="Description" />
                          </span>
                        </div>
                        &nbsp;&nbsp;
                        <div class="slds-col">
                          <span>
                               <lightning:inputField fieldName="Subject" />
                          </span>
                        </div>       
                    </div>
</aura:if>

component code

doInit: function(component, event, helper) {
    //Edit Case
    helper.caseTypeChangeHelperFun(component, event);                        
},  caseTypeChange : function(component, event, helper) {        
   helper.caseTypeChangeHelperFun(component, event);
},

Helper Code

 caseTypeChangeHelperFun: function(component, event){               
         var caseTypeIdValue=component.find("caseTypeId").get("v.value");  
         component.set("v.caseTypeValue", caseTypeIdValue);      
         console.log('--caseTypeIdValue---'+caseTypeIdValue); 
    },

Problem

  1. When I click on the 'case Type' pick list "request detail" section is showing perfectly.

  2. When I load the "Edit" page and if value is selected as "request" the related section is not showing. This is the problem.

4
  • can you update your question with where you want clarification? I mean, is there any parent component or child or any other condition? Your input field is defined in which component? Commented Aug 24, 2018 at 8:19
  • 1
    Hi Sanjay. Based on the question and the comments you've left for others, I believe your question is a duplicate in the general sense of what the resolution is (i.e. you cannot do what you're asking). Please read the other question/answer, and if you feel this does not satisfactorily answer your question, please let us know, and we'll be glad to re-open your question for you. You may comment on this question to let me know. Thanks!
    – sfdcfox
    Commented Aug 24, 2018 at 9:03
  • Now I updated my query with related screen shot, please suggest me something
    – Sanjay
    Commented Aug 24, 2018 at 9:50
  • I am using now "lightning:recordEditForm", could you please confirm me which one should i use now "lightning:recordEditForm" OR "force:recordData" please confirm
    – Sanjay
    Commented Aug 24, 2018 at 11:49

2 Answers 2

1

You can access aura:id value like this :

 var caseTypeidValue=component.find("caseTypeId").get("v.value"); //here you will the value
4
  • I want to access this value at "init" method not for on change event of lightning component, Yes you are right we can access value by this code but for the same component calling only
    – Sanjay
    Commented Aug 24, 2018 at 7:14
  • Keep that code in doInit.If you have value Input field you will get the value ,otherwise you will get undefined value
    – Annappa PH
    Commented Aug 24, 2018 at 7:37
  • Output: ----caseTypeId------undefined, when I put this in init method it returns "undefined", Please suggest some thing here to me
    – Sanjay
    Commented Aug 24, 2018 at 7:52
  • Now I updated my query with related screen shot, please suggest me something
    – Sanjay
    Commented Aug 24, 2018 at 9:50
0

By this way, you will get value in init method.

Component: 
Please add this in lightning component 
<lightning:inputField fieldName="Type" aura:id ="caseTypeId" id="caseTypeId1" value="10"/>   
<aura:handler name="init" value="{!this}" action="{!c.doInit}"/>

Controller:
({
    doInit: function(cmp) {
        var caseTypeidValue=cmp.find("caseTypeId").get("v.value"); 
    }
})
10
  • Output: ----caseTypeId------undefined, when I put this in init method it returns "undefined"
    – Sanjay
    Commented Aug 24, 2018 at 7:52
  • because in the code snippet you have once: 'cmp' and 'component.find'. Both have to be the same. So just change cmp in the doInit function to component
    – utm
    Commented Aug 24, 2018 at 8:06
  • As there is no value parameter, it is showing undefined. I have changed inputField declaration. It is accessible now. Commented Aug 24, 2018 at 8:12
  • I was already changed 'cmp' with 'component' but i was getting the same issue
    – Sanjay
    Commented Aug 24, 2018 at 8:24
  • you have to put value attribute also in lightning:inputField field. as you are not adding that attribute, it is showing undefined. If you add that it will work. Commented Aug 24, 2018 at 8:27

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .