InputfieldSelector

Visual selector builder for ProcessWire page-finding selectors

It renders an admin UI where users choose fields, operators, values, modifiers, subfields, and groups rather than typing raw selector strings.

$f = $modules->get('InputfieldSelector');
$f->name = 'filter';
$f->label = 'Filter pages';
$f->value = 'title%=processwire';
$form->add($f);

The editable value is a selector string. If initValue is configured, it acts as a locked selector prefix and the combined selector is available as lastSelector after assignment or processing.

For selector syntax, see Selectors. For shared Inputfield behavior, see Inputfield.

Expand all      API reference

Properties
PropertyTypeDefaultDescription
valuestring''Editable selector string shown in the visual builder.
initValuestring''Locked selector prefix.
lastSelectorstring''Last full selector built from initValue and editable value.
initTemplateTemplate|nullnullContext template used to scope fields.
addIconstring'plus-circle'Icon for the add-row link.
addLabelstring'Add Field'Label for the add-row link.
previewbooltrueShow the live selector preview.
counterbooltrueShow the ajax match counter.
allowAddRemovebooltrueAllow selector rows to be added and removed.
allowSystemCustomFieldsboolfalseInclude custom fields marked as system.
allowSystemNativeFieldsbooltrueInclude native fields such as id, name, and template.
allowSystemTemplatesboolfalseAllow system templates in template options.
allowSubselectorsbooltrueAllow subselector values such as children=[title%=x].
allowSubfieldsbooltrueAllow subfield selection such as page_ref.title.
allowSubfieldGroupsbooltrueAllow grouped page-reference subfields such as @field.title.
allowModifiersbooltrueAllow modifier fields such as include, limit, and sort.
allowBlankValuesboolfalsePreserve blank values as "" rather than omitting them.
showFieldLabelsbool|intfalseShow field labels instead of names; 2 shows both.
showOptgroupsbooltrueGroup field choices into system, fields, subfields, groups, modifiers, and adjustments.
limitFieldsarray[]Whitelist of selectable field names.
excludestring|array''Fields to exclude from selection.
parseVarsbooltrueParse selector variables such as [user.id].
previewColumnsstring|array[]Columns used in Lister preview bookmarks.
maxUsersint20Use text input for user fields when user count reaches this threshold.
maxSelectOptionsint100Use autocomplete for Page reference fields with more selectable pages than this.
selectClassstring''Extra class for generated selects.
inputClassstring''Extra class for generated inputs.
checkboxClassstring''Extra class for generated checkboxes.

Date/time settings:

PropertyDefault
dateFormat'Y-m-d'
datePlaceholder'yyyy-mm-dd'
timeFormat'H:i'
timePlaceholder'hh:mm'
Settings

getDefaultSettings()

Return factory defaults for configurable settings:

$defaults = $f->getDefaultSettings();

getSettings()

Return effective settings after merging defaults and instance values:

$f->preview = false;
$settings = $f->getSettings();
echo $settings['preview']; // false

The ready() method also applies optional global classes from $config->InputfieldSelector:

$config->InputfieldSelector = [
    'selectClass' => 'uk-select',
    'inputClass' => 'uk-input',
    'checkboxClass' => 'uk-checkbox',
];
Selector Info

setup()

Build internal operator, field, and modifier metadata. render() calls this automatically. Call it manually before using getSelectorInfo() for system or modifier fields.

$f->setup();

getSelectorInfo($field)

Return selector metadata for a system field, modifier field, field name, or Field object.

$f->setup();

$info = $f->getSelectorInfo('template');
$info = $f->getSelectorInfo($fields->get('title'));

The returned array can include keys such as input, label, operators, options, sanitizer, and subfields.

Sanitizing Selectors

sanitizeSelectorString($selectorString, $parseVars = true)

Normalize a selector string, prepend initValue, optionally parse variables, resolve username values for created_users_id / modified_users_id, and enforce the allowSubselectors setting.

$f->initValue = 'template=blog-post';
$selector = $f->sanitizeSelectorString('title%=api', false);
// template=blog-post, title%=api

When allowSubselectors is false, submitted subselectors are removed, an error is recorded, and a forced non-match selector is added.

$f->allowSubselectors = false;
$selector = $f->sanitizeSelectorString('children=[title%=api]', false);
// id<0
Processing Input

processInput(WireInputData $input)

Process submitted selector input and sanitize it. With no initValue, value contains the processed selector.

$form->processInput($input->post);
$selector = $f->val();

When initValue is populated, value stores the editable portion and lastSelector stores the full selector:

$f->initValue = 'template=blog-post';
$form->processInput($input->post);

$editable = $f->val();
$full = $f->lastSelector;

Use sanitizeSelectorString() directly when you need an immediate full selector from raw input.

Rendering

render()

Render the full visual selector builder:

echo $f->render();

Rendered output includes:

  • A <ul class="selector-list"> containing selector rows.
  • A hidden input containing the editable selector value.
  • Add/remove controls when allowAddRemove is enabled.
  • Preview and counter elements unless disabled.

renderRow($select, $subfield, $opval, $class = '')

Render one selector row wrapper from pre-rendered control markup.

$row = $f->renderRow($selectHtml, $subfieldHtml, $opvalHtml, 'custom-row');

This is mainly a small extension point for row markup.

Notes
  • Get an instance with $modules->get('InputfieldSelector').
  • Intended for admin/process-module contexts, not general public forms.
  • Ajax endpoints require a logged-in user and a valid rendered inputfield session state.
  • limitFields may include subfields like page_ref.title.
  • initValue is not rendered as editable rows; it is stored separately and represented in preview data.
  • Source file: wire/modules/Inputfield/InputfieldSelector/InputfieldSelector.module.

API reference: methods, properties, hooks

Concept by Avoine, Code by Ryan Cramer, Sponsored by Avoine


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

Show class?     Show args?       Only hookable?    

Common

NameReturnSummary 
InputfieldSelector::get(string $key)
mixed

Get property

 
InputfieldSelector::getDefaultSettings()
array

Return the default settings

 
InputfieldSelector::getParentPages(Template $template)
PageArray

Get parent pages of pages using the given template

 
InputfieldSelector::getSelectorInfo($field)
array

Returns an array of selector information for the given Field or field name

 
InputfieldSelector::getSettings()
array

Return the configured settings

 
InputfieldSelector::processInput(WireInputData $input)
$this

Process input submitted to this Inputfield

InputfieldSelector::render()
string

Primary Inputfield render method

InputfieldSelector::renderRow(string $select, string $subfield, string $opval)
string

Render a selector row <li>

 
InputfieldSelector::sanitizeSelectorString($selectorString)
string

Sanitize a selector string and return it

 
InputfieldSelector::set(string $key, mixed $value)
this Inputfield WireData

Set property

 
InputfieldSelector::setAttribute($key, $value)
InputfieldSelector WireData

Set an attribute to this Inputfield, overridden from Inputfield class

 
InputfieldSelector::setup()
None

Setup the shared structures and data used by Selector

 

Properties

NameReturnSummary 
InputfieldSelector::addIcon string [plus-circle] Icon used for the "Add Field" link. 
InputfieldSelector::addLabel string [Add Field] Text used for the "Add Field" link 
InputfieldSelector::allowAddRemove bool [true] Whether to allow adding new rows / removing existing rows 
InputfieldSelector::allowBlankValues bool [false] When no value is present, should it contribute to the selector? 
InputfieldSelector::allowModifiers bool [true] Allow use of modifiers like include, limit? 
InputfieldSelector::allowSubfieldGroups bool [true] Allow @grouping of subfields (like for page references)? 
InputfieldSelector::allowSubfields bool [true] Allow use of subfields? 
InputfieldSelector::allowSubselectors bool [true] Allow use of subselectors? 
InputfieldSelector::allowSystemCustomFields bool [false] Allow system custom fields to appear in field selects? 
InputfieldSelector::allowSystemNativeFields bool [true] Allow system native fields to appear in field selects? 
InputfieldSelector::allowSystemTemplates bool [false] Allow selection of system templates (user, role, etc.)? 
InputfieldSelector::checkboxClass string Extra CSS class for generated checkbox inputs.
DEFAULT: ''
 
InputfieldSelector::counter bool [true] Whether to show a live "number of matches" indicator. 
InputfieldSelector::dateFormat string [Y-m-d] Default PHP date() format for date fields. 
InputfieldSelector::datePlaceholder string [yyyy-mm-dd] Placeholder attribute text for date fields. 
InputfieldSelector::exclude string One or more (CSV) fields to disallow selection for 
InputfieldSelector::groupIdentifier string Label suffix used for grouped subfield selectors.
DEFAULT: (1)
 
InputfieldSelector::initTemplate Template null [null] Optional context template, used only just 1 allowed (pulled from $initValue automatically). 
InputfieldSelector::initValue string [selector string] Initial value that user can't change. 
InputfieldSelector::inputClass string Extra CSS class for generated input elements.
DEFAULT: ''
 
InputfieldSelector::lastSelector string Last full selector string built from initValue and value.
DEFAULT: ''
 
InputfieldSelector::limitFields array [empty] Selectable fields whitelist (field names). Leave empty to allow any. 
InputfieldSelector::maxSelectOptions int [100] If quantity of select options exceeds this number, use autocomplete instead for Page reference fields 3.0.148 
InputfieldSelector::maxUsers int [20] Maximum number of users selectable. If more than regular text input used rather than select. 
InputfieldSelector::optgroupsOrder string [system,field,subfield,group,modifier,adjust] Order and presence of field selection option groups. 
InputfieldSelector::parseVars bool [true] Whether variables in a selector should be parsed and converted to values 
InputfieldSelector::preview bool [true] Whether to show a live preview of selector in notes section. 
InputfieldSelector::previewColumns string array [name,template,id] Array or CSV string of columns to show in bookmark previews 
InputfieldSelector::selectClass string Extra CSS class for generated select elements.
DEFAULT: ''
 
InputfieldSelector::showFieldLabels bool int [false] Show field labels rather than names? Or specify integer 2 to show both. 
InputfieldSelector::showOptgroups bool [true] Whether or not to separate system, field, subfields, etc. into their own optgroups. If turned off, all types of fields will be shown together A-Z. 
InputfieldSelector::subfieldIdentifier string Label suffix used for fields that open a subfield selector.
DEFAULT:
 
InputfieldSelector::timeFormat string [H:i] Default PHP date() format for time component of date fields. 
InputfieldSelector::timePlaceholder string [hh:mm] Placeholder attribute time component of date fields. 
InputfieldSelector::value string [selector string] Value that user can change. 

Additional methods and properties

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

API reference based on ProcessWire core version 3.0.269