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 Collapse all API reference
| Property | Type | Default | Description |
|---|---|---|---|
value | string | '' | Editable selector string shown in the visual builder. |
initValue | string | '' | Locked selector prefix. |
lastSelector | string | '' | Last full selector built from initValue and editable value. |
initTemplate | Template|null | null | Context template used to scope fields. |
addIcon | string | 'plus-circle' | Icon for the add-row link. |
addLabel | string | 'Add Field' | Label for the add-row link. |
preview | bool | true | Show the live selector preview. |
counter | bool | true | Show the ajax match counter. |
allowAddRemove | bool | true | Allow selector rows to be added and removed. |
allowSystemCustomFields | bool | false | Include custom fields marked as system. |
allowSystemNativeFields | bool | true | Include native fields such as id, name, and template. |
allowSystemTemplates | bool | false | Allow system templates in template options. |
allowSubselectors | bool | true | Allow subselector values such as children=[title%=x]. |
allowSubfields | bool | true | Allow subfield selection such as page_ref.title. |
allowSubfieldGroups | bool | true | Allow grouped page-reference subfields such as @field.title. |
allowModifiers | bool | true | Allow modifier fields such as include, limit, and sort. |
allowBlankValues | bool | false | Preserve blank values as "" rather than omitting them. |
showFieldLabels | bool|int | false | Show field labels instead of names; 2 shows both. |
showOptgroups | bool | true | Group field choices into system, fields, subfields, groups, modifiers, and adjustments. |
limitFields | array | [] | Whitelist of selectable field names. |
exclude | string|array | '' | Fields to exclude from selection. |
parseVars | bool | true | Parse selector variables such as [user.id]. |
previewColumns | string|array | [] | Columns used in Lister preview bookmarks. |
maxUsers | int | 20 | Use text input for user fields when user count reaches this threshold. |
maxSelectOptions | int | 100 | Use autocomplete for Page reference fields with more selectable pages than this. |
selectClass | string | '' | Extra class for generated selects. |
inputClass | string | '' | Extra class for generated inputs. |
checkboxClass | string | '' | Extra class for generated checkboxes. |
Date/time settings:
| Property | Default |
|---|---|
dateFormat | 'Y-m-d' |
datePlaceholder | 'yyyy-mm-dd' |
timeFormat | 'H:i' |
timePlaceholder | 'hh:mm' |
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']; // falseThe ready() method also applies optional global classes from
$config->Inputfield
$config->InputfieldSelector = [
'selectClass' => 'uk-select',
'inputClass' => 'uk-input',
'checkboxClass' => 'uk-checkbox',
]; 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.
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%=apiWhen 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<0processInput(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.
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
allowAddRemoveis 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.
- Get an instance with
$modules->get('Inputfield.Selector') - Intended for admin/process-module contexts, not general public forms.
- Ajax endpoints require a logged-in user and a valid rendered inputfield session state.
limitFieldsmay include subfields likepage_ref.title.initValueis not rendered as editable rows; it is stored separately and represented in preview data.- Source file:
wire/modules/Inputfield/Inputfield.Selector/Inputfield Selector.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 Inputfield class also inherits all the methods and properties of: Inputfield, WireData and Wire.
Common
Properties
| Name | Return | Summary | |
|---|---|---|---|
| Inputfield | string | [plus-circle] Icon used for the "Add Field" link. | |
| Inputfield | string | [Add Field] Text used for the "Add Field" link | |
| Inputfield | bool | [true] Whether to allow adding new rows / removing existing rows | |
| Inputfield | bool | [false] When no value is present, should it contribute to the selector? | |
| Inputfield | bool | [true] Allow use of modifiers like include, limit? | |
| Inputfield | bool | [true] Allow @grouping of subfields (like for page references)? | |
| Inputfield | bool | [true] Allow use of subfields? | |
| Inputfield | bool | [true] Allow use of subselectors? | |
| Inputfield | bool | [false] Allow system custom fields to appear in field selects? | |
| Inputfield | bool | [true] Allow system native fields to appear in field selects? | |
| Inputfield | bool | [false] Allow selection of system templates (user, role, etc.)? | |
| Inputfield | string | Extra CSS class for generated checkbox inputs. DEFAULT: '' | |
| Inputfield | bool | [true] Whether to show a live "number of matches" indicator. | |
| Inputfield | string | [Y-m-d] Default PHP date() format for date fields. | |
| Inputfield | string | [yyyy-mm-dd] Placeholder attribute text for date fields. | |
| Inputfield | string | One or more (CSV) fields to disallow selection for | |
| Inputfield | string | Label suffix used for grouped subfield selectors. DEFAULT: (1) | |
| Inputfield | Template null | [null] Optional context template, used only just 1 allowed (pulled from $initValue automatically). | |
| Inputfield | string | [selector string] Initial value that user can't change. | |
| Inputfield | string | Extra CSS class for generated input elements. DEFAULT: '' | |
| Inputfield | string | Last full selector string built from initValue and value. DEFAULT: '' | |
| Inputfield | array | [empty] Selectable fields whitelist (field names). Leave empty to allow any. | |
| Inputfield | int | [100] If quantity of select options exceeds this number, use autocomplete instead for Page reference fields 3.0.148 | |
| Inputfield | int | [20] Maximum number of users selectable. If more than regular text input used rather than select. | |
| Inputfield | string | [system,field,subfield,group,modifier,adjust] Order and presence of field selection option groups. | |
| Inputfield | bool | [true] Whether variables in a selector should be parsed and converted to values | |
| Inputfield | bool | [true] Whether to show a live preview of selector in notes section. | |
| Inputfield | string array | [name,template,id] Array or CSV string of columns to show in bookmark previews | |
| Inputfield | string | Extra CSS class for generated select elements. DEFAULT: '' | |
| Inputfield | bool int | [false] Show field labels rather than names? Or specify integer 2 to show both. | |
| Inputfield | 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. | |
| Inputfield | string | Label suffix used for fields that open a subfield selector. DEFAULT: … | |
| Inputfield | string | [H:i] Default PHP date() format for time component of date fields. | |
| Inputfield | string | [hh:mm] Placeholder attribute time component of date fields. | |
| Inputfield | string | [selector string] Value that user can change. |
Additional methods and properties
In addition to the methods and properties above, Inputfield
API reference based on ProcessWire core version 3.0.269