Results 1 to 3 of 3

Thread: Adding a 'Please Select...' label to form:select form:options

  1. #1
    Join Date
    Nov 2009
    Posts
    28

    Lightbulb Adding a 'Please Select...' label to form:select form:options

    Not sure if others are having this problem, but I had to do a bit of research for a very simple and likely very common issue.

    Roo generated forms that create select lists default to the first value that the select is bound to. Not exactly a good default starting point in my mind.

    Here is an example of how you can improve an 'optional' select list to show a title value rather than defaulting to the first item in the list:

    Code:
                <div id="roo_staffprofile_person">
                    <c:if test="${not empty people}">
                        <label for="_person_id">Person:</label>
                        <form:select cssStyle="width:250px" id="_person_id" path="person">
                            <form:option value="0" label="--- Select ---" />
                            <form:options itemValue="id" items="${people}" itemLabel="KnownAs"/>
                        </form:select>
                        <script type="text/javascript">Spring.addDecoration(new Spring.ElementDecoration({elementId : '_person_id', widgetType: 'dijit.form.FilteringSelect', widgetAttrs : {hasDownArrow : true}})); </script>
                    </c:if>
                </div>

  2. #2
    Join Date
    Nov 2009
    Posts
    28

    Default

    Here is the link to Spring documentation:
    http://static.springsource.org/sprin...glib-optiontag

  3. #3
    Join Date
    Dec 2007
    Posts
    21

    Default

    Forms4j (www.forms4j.com) has a hint attribute that does exactly this -- along with automatic server side validation that ensures the "Please select..." option is not submitted.

    Code:
    <forms4j:select id="foo" hint="Please select...">
    	<forms4j:option value="apple" label="Apples" />
    	<forms4j:option value="orange" label="Oranges" />
    </forms4j:select>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •