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
Lightning PracticeLightning Practice 

how to make default values for picklist value in map?

Hi All,

Please help
how to make default values for picklist value in map?  
In main component i have sub component 
<aura:component>
<aura:attribute name="pickValuesMap" Type="Map" default="{}">

<c:caseComp metadata="{!v.pickValuesMap.Status}" value="{!v.Obj.Status}" isEdit="true"/>
</aura:component>



pickValuesMap am getting all the field values as here {"Name":"Case Number",other values,"Name":"Status","PicklistValues:["New","Open"]"}

How to Make  default picklist value  Status with "New"

Thanks,
Lightning Practice.  
Alain CabonAlain Cabon
Hi,

You should post the code for the component caseComp.

It is just a drop down list with a selected value or a real field of type picklist of an existing object (the "default" value is either the last stored value or the default value defined for the field itself).
 
Lightning PracticeLightning Practice
Hi Alain,

Thanks for the response.

In CaseComp am getting whole the Case Reocrd information from the Metadata.
Map holds all the case record information.All the picklist values retrieved from schema level.here the problem is picklist value is not default at schema level. I want to make it default in component level.
<aura:component>

<aura:attribute name="pickValuesMap" Type="Map" default="{}">
<aura:attribute name="Obj" Type="Case" default="{'SobjectType':'Case'}">


<c:caseComp metadata="{!v.pickValuesMap.Name}" value="{!v.Obj.Name}" isEdit="true"/>

<c:caseComp metadata="{!v.pickValuesMap.Type}" value="{!v.Obj.Type}" isEdit="true"/>


<c:caseComp metadata="{!v.pickValuesMap.Status}" value="{!v.Obj.Status}" isEdit="true"/>


-------other fields 
</aura:component>

By default status has to be 'New'.

Thanks,
Lightning Practice 
     
Alain CabonAlain Cabon
Hi,

Attribute of <option>: selected="{!item.selected}"

Generating Options On Initialization
Use an attribute to store and set the array of option value on the component. The following component calls the client-side controller to create options during component initialization.
 
<aura:component>
    <aura:attribute name="options" type="List" />
    <aura:attribute name="selectedValue" type="String" default="Red"/>
    <aura:handler name="init" value="{!this}" action="{!c.loadOptions}" />
    <lightning:select name="mySelect" label="Select a color:" aura:id="mySelect" value="{!v.selectedValue}">
         <aura:iteration items="{!v.options}" var="item">
            <option text="{!item.label}" value="{!item.value}" selected="{!item.selected}"/>
        </aura:iteration>
    </lightning:select>
</aura:component>

https://developer.salesforce.com/docs/component-library/bundle/lightning:select/documentation

 
Lightning PracticeLightning Practice
HI Alain,
This is not am expecting , 
Thanks for suggestion.

Thanks .
Lightning practice
Alain CabonAlain Cabon
<c:caseComp> is your code and you don't post it (we see only the interface) so we can just "imagine" it.

The interface of the component is not sufficient (c:caseComp). We solve this kind of problem very easily each day (<option>: selected) but that is your own code that is the problem.  
 
Lightning PracticeLightning Practice
Hi Alain,

As i am holding array of picklistvalues in object[]
 
<aura:atrribute name="options" type="Object[]"  default="[]"/> 

<lightning:select name="mySelect" label="Select a color:" aura:id="mySelect" value="{!v.Value}">
         <aura:iteration items="{!v.options}" var="item">
            <option text="{!item.label}" value="{!item.value}" selected="{!item.selected}"/>
        </aura:iteration>
    </lightning:select>

In the options am getting array of all Picklistvalues like type,status fields etc.
function:cmp,event,helper{

component.set('v.options',retrunvalues);


}


I need to  set default value for Status with new in controller.Js

please help is aprreciated.

Thanks ,
Lightnig Practice