Giter Club home page Giter Club logo

silverstripe-bootstrap-tagfield's Introduction

Bootstrap Tag Field for SilverStripe

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');
            })
    )

silverstripe-bootstrap-tagfield's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

silverstripe-bootstrap-tagfield's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.