InputfieldAsmSelect
Sortable multiple-selection widget
Extends [[InputfieldSelectMultiple]] — all option
management methods (addOption(), addOptions(), setOptions(), addOptionsString(),
etc.) are inherited and documented in [[InputfieldSelect]]. Returns an array value
where order is preserved (implements InputfieldHasSortableValue).
$f = $modules->get('InputfieldAsmSelect');
$f->name = 'categories';
$f->label = 'Categories';
$f->addOptions([1 => 'News', 2 => 'Events', 3 => 'Blog']);
$f->val([2, 1]); // pre-select Events and News, in that order
$form->add($f); See [[Inputfield]] for the shared Inputfield API (labels, collapsed states, showIf, rendering, processing, etc.).
| Property | Type | Default | Description |
|---|---|---|---|
sortable | bool | true | Allow drag-to-reorder of selected items |
addable | bool | true | Allow adding items to the selection |
deletable | bool | true | Allow removing items from the selection |
hideDeleted | bool | true | Remove items immediately when deleted; when false, marks for deletion |
deletedPrepend | string | '-' | Character prepended to deleted item values when hideDeleted is false |
hideWhenEmpty | bool | false | Hide the select when no options are available |
editLink | string | '' | URL pattern for item edit links, e.g. /admin/page/edit/?id={value} |
editLabel | string | (icon) | Label/icon for the edit link |
editLinkModal | string\|bool | true | Open edit link in modal (true), false to open inline, or 'longclick' for longclick-only modal |
editLinkOnlySelected | bool | true | Show edit link only for previously selected items, not newly added ones |
editLinkButtonSelector | string | '' | CSS selector for buttons that become modal buttons in the edit link |
usePageEdit | int\|bool | false | When used with FieldtypePage, auto-enables page editor links (modal) |
addItemTarget | string | 'bottom' | Where new selections appear: 'top' or 'bottom' |
animate | bool | false | Animate adding/removing of items |
removeLabel | string | (icon) | Label/icon for the remove button |
sortLabel | string | (icon) | Label/icon for the sort handle |
debugMode | bool | false | Keep original <select> visible for debugging |
Properties in the table above can be set directly on the Inputfield:
$f->sortable = false; // disable drag-to-reorder
$f->addable = false; // prevent adding new selections
$f->addItemTarget = 'top'; // new selections appear at the topFor setting multiple options at once, use setAsmSelectOptions():
$f->setAsmSelectOptions([
'sortable' => false,
'animate' => true,
'addItemTarget' => 'top',
]);The editLink property adds an edit icon next to each selected item, linking to a
URL where {value} is replaced by the item's option value.
$f->editLink = '/admin/page/edit/?id={value}';
$f->editLinkModal = true; // open in modal window (default)When used with a FieldtypePage field and usePageEdit is enabled, edit links are
configured automatically:
$f->usePageEdit = 1; // enables modal page editor links for selected pagesBy default (hideDeleted = true), removing an item immediately hides it from the
selected list. When hideDeleted is false, deleted items remain visible but are
marked for deletion, with their submitted values prepended with deletedPrepend
(default '-') so the receiving code can identify them.
$f->hideDeleted = false;
$f->deletedPrepend = '-'; // deleted item 'abc' is submitted as '-abc'- Selected item order is preserved after
processInput()—$f->val()returns values in the order the user arranged them. - Requires jQuery and jQuery UI (loaded automatically).
- The
sizeattribute fromInputfieldSelectMultipleis not used. - Source file:
wire/modules/Inputfield/InputfieldAsm Select/Inputfield Asm Select.module
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: InputfieldSelectMultiple, InputfieldSelect, Inputfield, WireData and Wire.
Common
Properties
| Name | Return | Summary | |
|---|---|---|---|
| Inputfield | string | Where to place new selected items in list: top or bottom DEFAULT: 'bottom' | |
| Inputfield | bool | Can items be added to selection? DEFAULT: true | |
| Inputfield | bool | Animate the the adding/removing of items in the list? DEFAULT: false | |
| Inputfield | bool | Debug mode keeps original select visible DEFAULT: false | |
| Inputfield | bool | Can items be removed from selection? DEFAULT: true | |
| Inputfield | float string | Opacity of deleted item, set to 1.0 to disable opacity adjustment (applicable only if hideDeleted=true) | |
| Inputfield | string | Deleted item values are prepended with this character in the form submission (applicable only if hideDeleted=true) DEFAULT: '-' | |
| Inputfield | string | Text used in the "edit" link (if editLink is populated) | |
| Inputfield | string | Optional URL options can link to with tag {value} replaced by option value, i.e. /path/to/page/edit?id={$value} | |
| Inputfield | string | Button selector for finding buttons that should become modal window buttons | |
| Inputfield | string bool | Whether the edit link (if used) should be modal or "longclick" for longclick modal only DEFAULT: true | |
| Inputfield | bool | When true, edit link only appears for items that were already selected DEFAULT: true | |
| Inputfield | bool | Use fieldset support? (for PW Fieldset types) DEFAULT: false | |
| Inputfield | bool | Hide items when deleted. If false, items remain but are marked for deletion DEFAULT: true | |
| Inputfield | bool | Hide the <select> when there are no items available to select? DEFAULT: false | |
| Inputfield | bool | Use the highlight feature? DEFAULT: false | |
| Inputfield | string | Text that precedes highlight of added item DEFAULT: 'Added: ' | |
| Inputfield | string | Text that precedes highlight of removed item DEFAULT: 'Removed: ' | |
| Inputfield | string | Text used in the "remove" link | |
| Inputfield | string | Sortable handle/icon | |
| Inputfield | bool | Should the list be sortable? DEFAULT: true | |
| Inputfield | int bool | Use page editor links for selected Page items, when user has edit permission? DEFAULT: false |
Additional methods and properties
In addition to the methods and properties above, Inputfield
API reference based on ProcessWire core version 3.0.267