Coder Social home page Coder Social logo

zyx-yii2-chosen's Introduction

This is a fork of https://github.com/RomeroMsk/yii2-chosen, made in attempt to keep up to date dependency of http://harvesthq.github.io/chosen/

UPD

Since version 1.4.2 Chosen provides compiled sourses also in bower package and separate repo https://github.com/harvesthq/bower-chosen

This fork is switching to bower sourses.

Chosen + Bootstrap 3 + Yii2

Credits

Chosen http://harvesthq.github.io/chosen/

Chosen Bootstrap Look & Feel https://github.com/dbtek/chosen-bootstrap (with my style fixes)

Installation

The preferred way to install this extension is through composer.

Either run

php composer.phar require "nex/yii2-chosen" "*"

or add

"nex/yii2-chosen" : "*"

to the require section of your application's composer.json file.

Usage

With a model

<?php
use nex\chosen\Chosen;
?>

<?= Chosen::widget([
    'model' => $model,
    'attribute' => 'selectable_attr',
    'items' => [1 => 'First item', 2 => 'Second item', 3 => 'Third item'],
    'multiple' => true,
]);?>

<?= $form->field($model, 'selectable_attr')->widget(
    Chosen::className(), [
        'items' => [1 => 'First item', 2 => 'Second item', 3 => 'Third item'],
        'disableSearch' => 5, // Search input will be disabled while there are fewer than 5 items
        'clientOptions' => [
            'search_contains' => true,
            'single_backstroke_delete' => false,
        ],
]);?>

Without a model

<?php
use nex\chosen\Chosen;
?>
<?= Chosen::widget([
    'name' => 'ChosenTest',
    'value' => 3,
    'items' => [1 => 'First item', 2 => 'Second item', 3 => 'Third item'],
    'allowDeselect' => false,
    'disableSearch' => true, // Search input will be disabled
    'clientOptions' => [
        'search_contains' => true,
        'max_selected_options' => 2,
    ],
]);?>

To override default placeholder strings you can add translated messages for Select an option (single select) and Select some options (multiple select) to your application message file. By default widget will use 'app' category to translate this strings, but you can set your own category by changing translateCategory option in widget configuration. For example, you can write this in application config file:

<?php
\Yii::$container->set('nex\chosen\Chosen', [
    'translateCategory' => 'my-app',
]);

Also you can override placeholder text when invoking widget (it can be useful for selects with small width):

<?php
use nex\chosen\Chosen;
?>
<?= Chosen::widget([
    'name' => 'ChosenTest',
    'value' => 3,
    'items' => [1 => 'First item', 2 => 'Second item', 3 => 'Third item'],

    'placeholder' => 'Select',
]);?>

zyx-yii2-chosen's People

Contributors

sdkiller avatar romeromsk avatar

Watchers

James Cloos avatar  avatar

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.