FieldtypeSelector

Stores a selector string, built visually using a selector builder input

The primary use case is allowing editors to configure a page-finding query per page — essentially a "saved search" that can be executed at runtime.

Value type

string — a ProcessWire selector string (e.g. "template=product, sort=-created, limit=10"). Empty value is an empty string ''.

Getting and setting values
// Get the stored selector and use it to find pages
$selector = $page->selector_field;
if($selector) {
    $results = $pages->find($selector);
    foreach($results as $result) {
        echo $result->title;
    }
}

// Set a selector string programmatically
$page->selector_field = 'template=product, sort=-created, limit=10';
$page->save('selector_field');

// Clear the value
$page->selector_field = '';
$page->save('selector_field');
Selectors

Stores text and supports fulltext/text-matching operators, the same as FieldtypeText:

// Find pages whose selector field contains a specific term
$pages->find('selector_field*="template=product"');

// Find pages with a non-empty selector field
$pages->find('selector_field!=""');
Notes
  • initValue: an enforced prefix selector that is always prepended to the stored value at runtime. For example, if initValue is 'template=product', the field always returns "template=product, [user portion]". The prefix is stripped before saving and re-prepended on wakeup — $page->selector_field always returns the full combined selector.
  • previewColumns: CSV of field names shown in the selector builder preview (e.g. 'name, template, parent').
  • Compatible fieldtypes: FieldtypeSelector and FieldtypeText.
  • Database column: data TEXT NOT NULL, FULLTEXT indexed.

InputfieldSelector settings

These settings are available on the SelectorField instance and are passed through to InputfieldSelector. The most commonly used ones:

PropertyDefaultDescription
previewtrueShow a live selector preview below the input
countertrueShow live match-count indicator
allowAddRemovetrueAllow adding/removing condition rows
allowModifierstrueAllow modifiers like limit, sort, include
allowSubselectorstrueAllow use of subselectors
allowSubfieldstrueAllow use of subfields
allowSystemNativeFieldstrueAllow native system fields (id, name, etc.)
allowSystemCustomFieldsfalseAllow system custom fields
allowSystemTemplatesfalseAllow selection of system templates
allowBlankValuesfalseInclude rows with no value in the selector
showFieldLabelsfalseShow field labels (true), names (false), or both (2)
showOptgroupstrueGroup fields by type in the select dropdown
limitFields[]Whitelist of selectable field names; empty = all
exclude''CSV of field names to exclude from selection
parseVarstrueParse and resolve variables in the selector
maxUsers20Max users in select before switching to text input
maxSelectOptionsMax select options before switching to autocomplete for page refs
dateFormat'Y-m-d'PHP date format for date fields
timeFormat'H:i'PHP time format for time portion of date fields
addLabel'Add Field'Label for the "add condition" link
addIcon'plus-circle'Icon for the "add condition" link
optgroupsOrder'system,field,subfield,group,modifier,adjust'Order of field option groups
API reference: methods, hooks

Click any linked item for full usage details and examples. Hookable methods are indicated with the icon. In addition to those shown below, the FieldtypeSelector class also inherits all the methods and properties of: Fieldtype, WireData and Wire.

Show class?     Show args?       Only hookable?    

Common

NameReturnSummary 
FieldtypeSelector::formatValue($page, $field, $value)
None
FieldtypeSelector::getCompatibleFieldtypes($field)
None
FieldtypeSelector::getConfigInputfields($field)
None
FieldtypeSelector::getDatabaseSchema(Field $field)
array

Return the database schema in specified format

 
FieldtypeSelector::getFieldClass()
string

Get the Field class to use for fields of this type

 
FieldtypeSelector::getInputfield($page, $field)
None 
FieldtypeSelector::getMatchQuery(DatabaseQuerySelect $query, string $table, string $subfield, string $operator, mixed $value)
DatabaseQuery DatabaseQuerySelect

Update a query to match the text with a fulltext index

 
FieldtypeSelector::getModuleInfo()
None 
FieldtypeSelector::sanitizeValue($page, $field, $value)
None 
FieldtypeSelector::sleepValue($page, $field, $value)
None
FieldtypeSelector::wakeupValue($page, $field, $value)
None

Additional methods and properties

In addition to the methods and properties above, FieldtypeSelector also inherits the methods and properties of these classes:

API reference based on ProcessWire core version 3.0.260