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
objectNameanyyesSee documentation for textField.
propertystringyesSee documentation for textField.
associationstringyesSee documentation for textfield.
positionstringyesSee documentation for textfield.
optionsanyyesA 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 -”).
valueFieldstringyesThe 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.
textFieldstringyesThe 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.
prependstringyesSee documentation for textField.
appendstringyesSee documentation for textField.
prependToLabelstringyesSee documentation for textField.
appendToLabelstringyesSee 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>