About Inputfield Selectize

Inputfield for the ProcessWire FieldtypePage.

Category Admin Helpers
Admin helper modules are those that provide helpful tools, UI enhancements or optimizations to the admin panel (excluding Fieldtype or Inputfield modules).
Release StateBeta
Close to stable, but users are advised to be cautious and test thoroughly.*
Authormacrura
Module Version1.0.2
Class NameInputfieldSelectize
Compatibility2.7, 3.0
Date AddedJune 15, 2016
Last UpdatedAugust 8, 2016
Recommended ByNew recommendations may take up to 1 day to appear.

Instructions

This module's files should be placed in /site/modules/InputfieldSelectize/
How to install or uninstall modules

README

InputfieldSelectize

A Inputfield to provide a select interface for Processwire CMS FieldtypePage using the (awesome) Selectize.js jQuery plugin, by Brian Reavis.

Processwire: http://processwire.com/

Selectize: https://github.com/selectize/selectize.js

Features

  • Custom designed options and items for any page select field.
  • Your select options can use any field or subfield on the page, but also sub-subfields, or any data you provide, since you are not limited by tag replacement: you control the precise data supplied to the options using a PHP array that returns data to the module, which is in turn supplied in JSON to the select as adata-dataattribute.
  • The plugin uses the JSON object for each option meaning you can do whatever you want with that data in designing your options/items.
  • Each instance lets you define which fields are searchable for the select
  • Your selects can use display logic based on the value of any field/data item, for example using ternery conditionals you can avoid empty parenthesis.
  • You can design the options and items (what is seen once an option is selected) independently of each other. Therefore you could have special fields on the options for searching, but exclude those on the item. Likewise you can show elements on your item like an edit button which is not needed on the option.
  • Multiselect pages are sortable, and deletable by backspace or optional remove button.
  • When AceExtended editor is installed, the module will use that for the code input fields.

Usage

  • Install the Module
  • Edit your pagefield and choose InputfieldSelectize as inputfield.

Notes


Examples

Basic Example

PHP:

$data = array(
    'title' => $page->title,
    'company' => $page->company_select ? $page->company_select->title : 'Not set',
    'total' => count($page->recipients),
    'editUrl' => $page->editUrl
);

return $data;

Javascript (item and option same)

'<div class="item">' +
'<span style="display:block;font-size:14px;font-weight:bold;">' + escape(item.title)  + ' (' + escape(item.total) + ')</span>' +
'<span>' + escape(item.company) + '</span>' +
'</div>'

Example screenshot: "Example Screenshot"


A more advanced example

This example shows how to use conditionals for the PHP and JS to get the select options to look clean and provide the necessary information to assist users in choosing the correct options:

Multi Page

PHP

$data = array(
  'title' => $page->title,
  'year' => $page->year ?: $page->year_sort,
  'for_inst' => $page->for_inst,
  'edit_href' => $page->editUrl
);

return $data;

Item:

'<div class="item">' +
'<div style="color: black; font-size: 14px;"><span style="font-weight:bold;">' + escape(item.title) + ' (' + escape(item.year) + ')</span>' +
' <a class="pw-modal pw-modal-medium" href="' + escape(item.edit_href) + '">Edit <i class="fa fa-edit"></i></a></div>' +
(item.for_inst ? '<div style="color:gray;">for ' + escape(item.for_inst) + '</div>' : '') +
'</div>'

Option:

'<div class="item" style="width:100%;">' +
'<div style="color: black; font-size: 14px;"><span style="font-weight:bold;">' + escape(item.title) + ' (' + escape(item.year) + ')</div>' +
(item.for_inst ? '<div style="color:gray;">for ' + escape(item.for_inst) + '</div>' : '') +
'</div>'

Example with images

In this example the selects will feature a thumbnail image: "Page/Image"

You could also set the width of the selected item to 100% depending on where you place the field (e.g. in a column) "Image width 100"

$image = $page->images->first();
$thumb = $image->size(100,100);

$data = array(
	'title'       => $page->title,
    'thumb_src'   => $thumb ->url,
    'img_dims'    => $image->width . 'x' . $image->height,
    'img_desc'    => $image->description,
    'img_size'    => $image->filesizeStr,
    'edit_src'	  => $page->editUrl
);

return $data;
'<div class="item" style="width:100%;">' +
	'<div class="image-wrapper" style="float:left;"><img src="' + escape(item.thumb_src) + '" alt=""></div>' +
	'<div class="info-wrapper" style="float:left; padding:5px;">' +
    '<span style="font-size:14px;font-weight:bold">' + escape(item.title) + '</span><br>' +
		'<span>Dimensions: ' + escape(item.img_dims) + 'px</span><br>' +
		'<span>Filesize: ' + escape(item.img_size) + '</span><br>' +
		'<span>' + escape(item.img_desc) + '</span><br>' +
		'<a class="pw-modal pw-modal-medium" href="' + escape(item.edit_src) +
		'">Edit <span class="ui-icon ui-icon-extlink"></span></a></div>' +
'</div>'
'<div class="item">' +
	'<div class="image-wrapper" style="float:left;"><img src="' + escape(item.thumb_src) + '" alt=""></div>' +
	'<div class="info-wrapper" style="float:left; padding:5px;">' +
    '<span style="font-size:14px;font-weight:bold">' + escape(item.title) + '</span><br>' +
	'</div>' +
'</div>'

Comments

No comments yet. Be the first to post!

Post a Comment

Your e-mail is kept confidential and not included with your comment. Website is optional.