0

After search for a few hours...I found the answer to my problem from this question: How to populate a select list using a structure inside select HTML helper in ColdBox?

This example is perfect since I wasn't able to find anything on the ColdBox Doc. I used the "simple-form" for my Options... the result display is correct. However, the selectedValue does not seem to work when the value is a "". I also tried populating the Options from an array. I had the same issue for both method when it comes setting selectedValue is .

When the value is "", the first value in the Options always gets selected. How do I fix this or how do I change the Options to display "Select..." for when a selectedValue is ?

    #html.select(
                name="Approved",                    
                options="Yes,No,Pending",
                column="value",
                selectedValue="", 
                label="",
                required="required",
                title="Approved"
            )#
Community
  • 1
  • 1
Tuannie
  • 1
  • 3

1 Answers1

0

You need to create an array of objects containing a name and value pair for blank option, along with the rest of options:

<cfset foo = [
                {"name"= "Select", "value"= ""}
              , {"name"= "Yes", "value"= "Yes"}
              , {"name"= "No", "value"= "No"}
              , {"name"= "Pending", "value"= "Pending"}
             ] />

And pass the array to the select helper function using html.options() method.

#html.select(
            name="Approved",                    
            options=html.options(foo),
            selectedValue="",
            label="",
            required="required",
            title="Approved"
        )#

Note: In this case you don't need to provide column attribute. This may solve your problem.

Pankaj
  • 1,731
  • 1
  • 13
  • 15