1

My understanding of the text-property from the ui:inputSelectOption is that I can add underlaying data (in difference to the label-property which displays the data on the GUI-Interface). In my opinion this example should work without any issues:

<aura:component>

<aura:attribute name="dataProvider" type="Object[]" access="global" 
    default="[{name: 'Tom'}, {name: 'Bob'}, {name: 'Tim'}]" />

<ui:inputSelect>
    <aura:iteration items="{!v.dataProvider}" var="dataItem" indexVar="dataIndex">
            <ui:inputSelectOption label="{!dataItem.name}" text="{!dataIndex}" />
    </aura:iteration>
</ui:inputSelect>

But I cannot change the selection of the input select - it always jumps back to the first entry (Mac OS X, Chrome, Lightning Experience): enter image description here

enter image description here

enter image description here

Is this a bug? When I hardcode the inputSelectOptions by not using aura:iteration everything works fine. Same when I do not assign the text-property.

2

Trying it on my end... something funky definitely happening there, having to do with binding a numeric value to that text field. Here is my stupid hack of a fix:

<aura:attribute name="dataProvider" type="Map[]" access="global" 
                default="[{name: 'Tom'}, {name: 'Bob'}, {name: 'Tim'}]" />

<ui:inputSelect>
    <aura:iteration items="{!v.dataProvider}" var="dataItem" indexVar="dataIndex">
        <ui:inputSelectOption label="{!dataItem.name}" text="{!''+dataIndex}" />
    </aura:iteration>
</ui:inputSelect>

Adding '' + the index ensures it treats it as a string and that seems to unbreak the select list.

Note also that you can bind a Map[] directly to the items property of ui:inputSelect. For example:

<aura:attribute name="items" type="Map[]" access="global" 
                default="[{label: 'Tom', value:0}, {label: 'Bob', value:1}, {label: 'Tim', value:2}]" />

<ui:inputSelect options="{!v.items}" />
1
  • Thank you Charles - interesting point by using string concatenation. My original thought was to use an rich object from my data model for the text value but this works neither. Best in my eyes would be the support of data- attributes on ui components Jul 6 '16 at 15:06
0

I would use the same value for the label and the text attributes:

<aura:attribute name="dataProvider" type="Map[]" access="global" 
            default="[{name: 'Tom'}, {name: 'Bob'}, {name: 'Tim'}]" />

<ui:inputSelect>
    <aura:iteration items="{!v.dataProvider}" var="dataItem" indexVar="dataIndex">
        <ui:inputSelectOption label="{!dataItem.name}" text="{!dataItem.Name}" />
    </aura:iteration>
</ui:inputSelect>
1
  • Thank you for your idea, but in a real-world-scenario I would have a more complex data structure which is associated with the selected item so there is a need to bind data somehow - as ui:inputSelectOption is not supporting data-attributes the text property is the only way as I see Jul 8 '16 at 6:43

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.