dropdownplaceholderselectlistliferay-aui

placeholder in <aui:select> for dropdown liferay


How can I have a placeholder value in a dropdown ? Something a user will be shown in a dropdown but he will not be able to 'Select' that option.

For example: I'll have a placeholder as 'Please Select an Item' as a selected text in dropdown(placeholder) but user will not be able to select 'Please Select an Item' as an item from dropdown list.

Currently I do have to use things as shown in below code

<aui:select label="" id="admin" name="optionsSelect">
    <aui:option value="1">Please Select an Item</aui:option>
    <aui:option value="2">Item1</aui:option>                       
    <aui:option value="3">Item2</aui:option>                            
    <aui:option value="4">Item3</aui:option>                            
    <aui:option value="5">Item4</aui:option>    
</aui:select>

Solution

  • the only option to have a select with something like a placeholder is to add as you did a first option to the select, but adding also the options "selected" and "disabled" and its value empty, that is:

    <aui:select label="" id="admin" name="optionsSelect">
        <aui:option value="" selected="true" disabled= "true">Please Select an Item</aui:option>
        <aui:option value="2">Item1</aui:option>                       
        <aui:option value="3">Item2</aui:option>                            
        <aui:option value="4">Item3</aui:option>                            
        <aui:option value="5">Item4</aui:option>    
    </aui:select>
    

    Hope that help.