Form control: Object Picker
The objectPicker
control allows users to select one or multiple records from a given preside object. Configuration options also allow you to add new records and edit existing records from within the form control.
Set object picker default sort order
To specify object default sort order for object picker, use the @objectPickerDefaultSortOrder
annotation. For example:
// /application/preside-objects/author.cfc
/**
* @objectPickerDefaultSortOrder post_count desc
*/
component {
property name="name" type="string" dbtype="varchar" maxlength="200" required=true uniqueindexes="name";
property name="posts" relationship="one-to-many" relatedto="blog_post" relationshipkey="blog_author";
property name="post_count" type="numeric" formula="Count( ${prefix}posts.id )";
}
Arguments
object (required) | Name of the object whose records the user can select |
---|---|
ajax (optional) | True (default) or false. Whether or not to fetch records for the picker using Ajax. |
objectFilters (optional) | String list of saved preside object filters. See Data objects |
prefetchUrl (optional) | When ajax is set to "true", you can additionally supply a specific URL for fetching records to pre-populate the drop down |
remoteUrl (optional) | When ajax is set to "true", you can additionally supply a specific URL for fetching records to match typed searches |
useCache (optional) | True (default) or false. Whether to use caching when selecting data for this form field and its respective ajax lookup and prefetch. |
orderBy (optional) | Specify which column(s) to sort the select list on. Default is "label", which sorts alphabetically on the text displayed in the picker. |
placeholder (optional) | Message to appear prompting the user to search for records |
multiple (optional) | True of false (default). Whether or not to allow multiple record selection |
sortable (optional) | True or false (default). Whether or not to allow multiple selected records to be sortable within the control. |
searchable (optional) | True (default) or false. Whether or not the search feature of the control is enabled. |
resultTemplate (optional) | A Mustache template for rendering items in the drop down list. The default is "{{text}}". This can be used in conjunction with a custom remote URL for providing a highly customized object picker. |
selectedTemplate (optional) | A Mustache template for rendering selected items in the control. The default is "{{text}}". This can be used in conjunction with a custom remote URL for providing a highly customized object picker. |
quickAdd (optional) | True of false (default). Whether or not the quick add record feature is enabled. If enabled, you should create a /forms/preside-objects/(objectname)/admin.quickadd.xml form that will be used in the quick add dialog. |
quickAddUrl (optional) | If quickAdd is enabled, you can additionally set a custom URL for providing the quick add form. |
superQuickAdd (optional, 10.10.38 and above) | True of false (default). Whether or not the super quick add record feature is enabled. The super quick add feature allows you to add records inline when the search text entered does not exactly match any existing records. Note: the target object must be enabled for data manager. |
superQuickAddUrl (optional, 10.10.38 and above) | If superQuickAdd is enabled, you can additionally set a custom URL for processing the super quick add request. The URL will receive a POST request with a value field and should return a json object with text (label) and value (id) fields. |
quickEdit (optional) | True of false (default). Whether or not the quick edit record feature is enabled. If enabled, you should create a /forms/preside-objects/(objectname)/admin.quickadd.xml form that will be used in the quick edit dialog. |
quickEditUrl (optional) | If quickEdit is enabled, you can additionally set a custom URL for providing the quick edit form. |
bypassTenants (optional) | A comma separated list of tenants to ignore when populating the dropdown. See Configuring data tenancy. |
filterBy (optional) | An optional comma separated list of fields to filter the selectable data on. These fields can be present in either the form, URL parameters, or in any data set using event.includeData(). |
filterByField (optional) | An optional comma separated list of database field names to correspond with the fields defined in the filterBy attribute. Only necessary when the database fieldnames differ from the field names used to get the values for the filter. |
disabledIfUnfiltered (optional) | true or false and only to be used in conjunction with the filterBy attribute. If true and the filterBy field(s) are empty, the control will be disabled until the field(s) have value. |
Example
<field name="categories" control="objectPicker" object="blog_category" multiple="true" sortable="true" quickAdd="true" quickEdit="true" />
Example with caching disabled
<field name="categories" useCache="false" control="objectPicker" object="blog_category" multiple="true" sortable="true" quickAdd="true" quickEdit="true" />