unclecheese/bootstrap-tagfield

Allows you to create field that allows multiple selection of records, such as tags, compliant with Bootstrap 3

Installs: 12 497

Dependents: 0

Suggesters: 0

Security: 0

Stars: 6

Watchers: 4

Forks: 6

Open Issues: 4

Language:JavaScript

Type:silverstripe-module

dev-master 2015-01-05 23:39 UTC

This package is auto-updated.

Last update: 2024-02-29 02:18:27 UTC


README

Creates a field that allows multiple selection, like a CheckboxSetField to store in a many_many, has_many, or native field (as comma separated values) and provides typeahead searching with prefetching and caching on a given result set. Useful for multiple selection of a densely populated data set, like tags.

This field is only for frontend forms using the Bootstrap framework. It will not render properly in the CMS.

Screenshot

screenshot

Installation

composer require unclecheese/bootstrap-tagfield:dev-master

Requirements

  • silverstripe/framework 3.1.*
  • unclecheese/bootstrap-forms 1.1.*

Usage

A simple tag field that queries against a list of all Tag records.

BootstrapTagField::create('Tags', 'Add some tags below', Tag::get());

This field is not only for tags. It can be used as a replacement for checkboxes when the data set is large.

BootstrapTagField::create(
  'Categories', 
  'Add categories to your product', 
  ProductCategory::get()
    ->filter('Available', true)
);

Optional arguments

Set the field to be used as the label (e.g. the text of a checkbox field). Defaults to Title.

BootstrapTagField::create('Tags', 'Add some tags below', Tag::get(), 'Name');

Set the field to be used as the ID of the option (e.g. the value that is stored in the database). Defaults to ID.

BootstrapTagField::create('Tags', 'Add some tags below', Tag::get(), 'Name', 'Slug');

Prefetching

You can optionally provide a SS_List to be loaded into the typeahead search to give immediate results. Once an actual query is made to the remote, the list is backfilled with any new results that come through.

Prefetch a list of popular tags:

BootstrapTagField::create('Tags', 'Add some tags below', Tag::get())
    ->setPrefetch(
        Tag::get()
            ->leftJoin('Post_Tags', 'TagID = Tag.ID')                            
            ->sort('COUNT(Tag.ID)','DESC')
            ->limit(30)
            ->alterDataQuery(function($query) {
                $query->groupby('Tag.ID');
            })
    )