Announcement Announcement Module
Collapse
No announcement yet.
Adding a 'Please Select...' label to form:select form:options Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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
    Here is the link to Spring documentation:
    http://static.springsource.org/sprin...glib-optiontag

    Comment


    • #3
      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>

      Comment

      Working...
      X