0

I have two picklist fields, Country(controllling picklist) and State(dependent picklsit). State should change based on Country value for my lightning page. As of now this is happening, but State field doesn't come on page when page gets load, it does when I make any change in Country Value. I want both the fields should be shown on page whenever page loads for first time and, also dependency should work.

Please find codes below -

CMP CODE:

<aura:attribute name="recordId" type="Id" access="public" />
    <aura:attribute name="refreshFag" type="boolean" access="public" default="false" />
    <div class="slds-grid slds-gutters" style="margin-left:2px;">
                <table>
                    <tr>
                        <lightning:recordEditForm aura:id="recordViewForm" recordId="{!v.recordId}"
                                                  objectApiName="Opportunity">
                            <lightning:messages />
                            <td>
                                <label for="Country">Country</label>
                                <lightning:inputField aura:id="countyId" fieldName="Property_Country__c"
                                                      variant="label-hidden"
                                                      onchange="{!c.setStateRefresh}" />

                            </td>
                            <aura:if isTrue="{!v.refreshFag}"> 
                                <td>
                                    <label for=" State / Province ">State / Province</label>
                                    <lightning:inputField aura:id="stateId" fieldName="Property_State__c" 
                                                          variant="label-hidden"/>
                                </td>
                            </aura:if>
                        </lightning:recordEditForm>
                    </tr>
                </table>
            </div><br/> 

JS CODE:

            setStateRefresh : function(component, event, helper) {  
        var refresh = component.set("v.refreshFag","true");
        //alert('v.refreshFag---->'+refresh);
    }
7
  • i dont quite understand what your question is, nor what your issue is. what do you mean by "I want both the fields Country and State altogether whenever page gets load"
    – glls
    Jul 21, 2018 at 14:35
  • I have edited the question. I hope it's understandable now.
    – Ludic8
    Jul 21, 2018 at 15:42
  • if you remove your conditional rendering, both fields will display, i'm not sure why you have that condition, what is the purpose of the refreshTag? Id doesnt seem to serve any purpose
    – glls
    Jul 21, 2018 at 16:19
  • Because dependency won't work otherwise. It will work first time when page executes, since it will take values from Record Page(back-end) , but if I change country, same won't reflect for State. Value for State remains as previous value, even we change value for Country because State field won't get refresh. I hope you get my point.
    – Ludic8
    Jul 21, 2018 at 16:37
  • No, I don’t. Dependency does work with the recordeditform component out of the box, the controlling field will be editable at first, and the dependant picklist will be disabled until you select a value from the controlling field
    – glls
    Jul 21, 2018 at 16:42

1 Answer 1

1

Dependency works with the recordeditform component out of the box, the controlling field will be editable at first, and the dependant picklist will be disabled until you select a value from the controlling field.

Your aura:if is not serving any purpose since your setStateRefresh methof is being triggered on page load.

I just setup some dep. picklists on opportunity to simulate what you are doing and the form is doing its job as intended:

enter image description here

it is also respecting the field dependencies I set: enter image description here

2
  • Worked, thanks again! Can we put default value for Country picklist here, that doesn't match with record page value.
    – Ludic8
    Jul 21, 2018 at 17:19
  • Not out of the box, you would have to code that
    – glls
    Jul 21, 2018 at 17:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.