-1

I would like to set default value as "all" after loading the page. how to set"all"in case of page load

<aura:attribute name="options" type="List" default="all"/>
   <div class="slds-grid slds-gutters">
     <div class="slds-col">
         <span>
             <div class="slds-form-element">
                 <ui:inputSelect aura:id="Aircraft Manufacturer"   label="Aircraft Manufacturer" change="{!c.FindAllChanges}">

                  <aura:iteration items="{!v.options}" var="item">                          
                        <ui:inputSelectOption text="{!item.label}" value="{!item.value}"  label="{!Document}"  />
                    </aura:iteration>

                </ui:inputSelect>    

            </div>
        </span>
    </div>

({
doInit: function(component, event, helper) {
    helper.Displayaircraftmanufacturer(component, 
  'Aircraft_Manufacturer__c', 'Aircraft Manufacturer');
 }

   ({
     Displayaircraftmanufacturer : function(component, fieldName,elementId )  {
    var action = component.get("c.getselectOptions");
    action.setParams({
        "objObject": component.get("v.objInfo"),
        "fld": fieldName
    });
    var opts = [];
    action.setCallback(this, function(response) {
        if (response.getState() == "SUCCESS") {

            var allValues = response.getReturnValue();

            if (allValues != undefined && allValues.length > 0) {
                opts.push({

                    label: "All",
                    value: ""
                });
            }
            for (var i = 0; i < allValues.length; i++) {
                opts.push({

                    label: allValues[i],
                    value: allValues[i]
                });
            }

           // component.find(elementId).set("v.options[0]", opts);
           component.set("v.options",opts)

        }

    });
    $A.enqueueAction(action);
}
1

"value" should be set to "true" when selected, and "false" when not.

        if (allValues != undefined && allValues.length > 0) {
            // default selected
            opts.push({ label: "All", value: true });
            // All others not selected
            allValues.forEach(label => opts.push({ label: label, value: false });
        }
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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