Skip to content

Miscellaneous

select()

select() — returns any

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.

NameTypeRequiredDefaultDescription
objectNameanyyes—See documentation for textField.
propertystringyes—See documentation for textField.
associationstringyes—See documentation for textfield.
positionstringyes—See documentation for textfield.
optionsanyyes—A collection to populate the select form control with. Can be a query recordset or an array of objects.
includeBlankanyyesfalseWhether 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 -”).
valueFieldstringyes—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.
textFieldstringyes—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.
labelstringyesuseDefaultLabelSee documentation for textField.
labelPlacementstringyesaroundSee documentation for textField.
prependstringyes—See documentation for textField.
appendstringyes—See documentation for textField.
prependToLabelstringyes—See documentation for textField.
appendToLabelstringyes—See documentation for textField.
errorElementstringyesspanSee documentation for textField.
errorClassstringyesfieldWithErrorsSee documentation for textField.
<!--- 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>