You need to sign in to do that
Don't have an account?
Joseph Murawski
Losing picklist selected value during page refresh
I have created a lightning component that uses
<div class="slds-truncate" title="{!v.fieldLabel}">
<label class="slds-form-element__label">{!v.fieldLabel}</label> <br />
<ui:inputSelect aura:id="inputCell" class="slds-input" value="{!v.fieldData}">
<aura:iteration items="{!v.options}" var="statusOption">
<ui:inputSelectOption text="{!statusOption.value}" label="{!statusOption.label}" />
</aura:iteration>
</ui:inputSelect>
</div>
to select from a picklist value. In the save routine I end with $A.get('e.force:refreshView').fire(); to refresh all the components on the page. When this takes place, the selected value in the picklist is no longer selected and shows the first value in the list.
I tried re-calling the doInit function but it fires before the refresh is complete and does not fix this.
Any ideas on what I can do to fix this issue?
<div class="slds-truncate" title="{!v.fieldLabel}">
<label class="slds-form-element__label">{!v.fieldLabel}</label> <br />
<ui:inputSelect aura:id="inputCell" class="slds-input" value="{!v.fieldData}">
<aura:iteration items="{!v.options}" var="statusOption">
<ui:inputSelectOption text="{!statusOption.value}" label="{!statusOption.label}" />
</aura:iteration>
</ui:inputSelect>
</div>
to select from a picklist value. In the save routine I end with $A.get('e.force:refreshView').fire(); to refresh all the components on the page. When this takes place, the selected value in the picklist is no longer selected and shows the first value in the list.
I tried re-calling the doInit function but it fires before the refresh is complete and does not fix this.
Any ideas on what I can do to fix this issue?
Thanks for talking things through with me. I figured out my issue.
<ui:inputSelect aura:id="inputCell" class="slds-input" value="{!v.fieldData}">
<aura:iteration items="{!v.options}" var="statusOption">
<ui:inputSelectOption text="{!statusOption.value}" label="{!statusOption.label}" />
</aura:iteration>
</ui:inputSelect>
I have this formatted wrong.
I should have options="{!v.options}" in the ui:inputSelect and not include the ui:inputSelectOption at all.
I made the change and it works like a charm.
Again, thanks for looking.
Joe
All Answers
Greetings to you!
You can call same method in both handlers, i.e; init and refreshView
Something like this:
We can use the same action method for multiple handlers. Here, you just need to refresh the component. So, it can be done by calling doInit method which will initialize the component again. The init handler is defined to execute some code when the component is initialized.
If the problem still persists, I suggest you please share the complete code.
I hope it helps you.
Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future. It will help to keep this community clean.
Thanks and Regards,
Khan Anas
I went to share the code and it exceeds the 32K limit here. How do people normally upload the code examples?
Please refer below screenshots.
Regards,
Khan Anas
Component
Controller:
Helper:
Apex Controller:
Design:
There is no problem with the refresh part. It is working fine. In doInit method you are fetching picklist values dynamically and it is storing in ui:inputSelect as it is coming from server. So, on refresh also it is doing the same thing. You are not fetching the record picklist value which is stored in database. If you want to display the stored picklist value then you need to fetch it from the particular record accordingly.
I hope it helps you!
Kindly mark this as solved if the information was helpful. It will help to keep this community clean.
Regards,
Khan Anas
I am implementing your code in my developer org. Can you please share CommonFunctions class as well as there is some dependency on below line of code.
retVal = sObjLabel + '|' + CommonFunctions.parseLEXJSON(JSON.serialize(sObj), fieldName);
Regards,
Khan Anas
Thanks for talking things through with me. I figured out my issue.
<ui:inputSelect aura:id="inputCell" class="slds-input" value="{!v.fieldData}">
<aura:iteration items="{!v.options}" var="statusOption">
<ui:inputSelectOption text="{!statusOption.value}" label="{!statusOption.label}" />
</aura:iteration>
</ui:inputSelect>
I have this formatted wrong.
I should have options="{!v.options}" in the ui:inputSelect and not include the ui:inputSelectOption at all.
I made the change and it works like a charm.
Again, thanks for looking.
Joe