Miscellaneous
select()
Signature
Section titled “Signature”select() — returns any
Description
Section titled “Description”Builds and returns a string containing a select form control based on the supplied objectName and property. Note: Pass any additional arguments like class, rel, and id, and the generated tag will also include those values as HTML attributes.
Parameters
Section titled “Parameters”| Name | Type | Required | Default | Description |
|---|---|---|---|---|
objectName | any | yes | — | See documentation for textField. |
property | string | yes | — | See documentation for textField. |
association | string | yes | — | See documentation for textfield. |
position | string | yes | — | See documentation for textfield. |
options | any | yes | — | A collection to populate the select form control with. Can be a query recordset or an array of objects. |
includeBlank | any | yes | false | Whether to include a blank option in the select form control. Pass true to include a blank line or a string that should represent what display text should appear for the empty value (for example, ”- Select One -”). |
valueField | string | yes | — | The column or property to use for the value of each list element. Used only when a query or array of objects has been supplied in the options argument. |
textField | string | yes | — | The column or property to use for the value of each list element that the end user will see. Used only when a query or array of objects has been supplied in the options argument. |
label | string | yes | useDefaultLabel | See documentation for textField. |
labelPlacement | string | yes | around | See documentation for textField. |
prepend | string | yes | — | See documentation for textField. |
append | string | yes | — | See documentation for textField. |
prependToLabel | string | yes | — | See documentation for textField. |
appendToLabel | string | yes | — | See documentation for textField. |
errorElement | string | yes | span | See documentation for textField. |
errorClass | string | yes | fieldWithErrors | See documentation for textField. |
Examples
Section titled “Examples”<!--- Example 1: Basic `select` field with `label` and required `objectName` and `property` arguments --->
<!--- - Controller code --->
<cfset authors = model("author").findAll()>
<!--- - View code --->
<cfoutput>
<p>#select(objectName="book", property="authorId", options=authors)#</p>
</cfoutput>
<!--- Example 2: Shows `select` fields for selecting order statuses for all shipments provided by the `orders` association and nested properties --->
<!--- - Controller code --->
<cfset shipment = model("shipment").findByKey(key=params.key, where="shipments.statusId=##application.NEW_STATUS_ID##", include="order")>
<cfset statuses = model("status").findAll(order="name")>
<!--- - View code --->
<cfoutput>
<cfloop from="1" to="##ArrayLen(shipments.orders)##" index="i">
#select(label="Order #shipments.orders[i].orderNum#", objectName="shipment", association="orders", position=i, property="statusId", options=statuses)#
</cfloop>
</cfoutput>