romeromsk / yii2-chosen Goto Github PK
View Code? Open in Web Editor NEWChosen widget for Yii2 (with Bootstrap3)
License: BSD 3-Clause "New" or "Revised" License
Chosen widget for Yii2 (with Bootstrap3)
License: BSD 3-Clause "New" or "Revised" License
Good Day,
greetins Romero, i use your chosen extension and it´s amazing because works with BootStrap 3, but i have a newbie question, how to store array into database and get back on the view render for chosen?
what i do:
Database Exception – yii\db\Exception
PDOStatement::bindValue() expects parameter 2 to be long, string given
Failed to prepare SQL: INSERT INTO
Caused by: yii\base\ErrorException
PDOStatement::bindValue() expects parameter 3 to be long, string given
in C:\websites\reportes2\vendor\yiisoft\yii2\db\Command.php at line 271
5 so i try to convert it into string using implode(",", $model->miembros);
but when got back to the form if are multiple items they not show on the input.
The sentence "No results found" is hard-coded. It would be nice for an user to be able to change it through the Chosen object's settings.
Hi. Please help me.
I'm trying to apply plugin to few form on one page, but chоsen applies to only for one select!
The forms on page is the same model.
This is my code:
<div class="form-group">
<?php echo Html::activeLabel($model,'geo')?>
<?= \nex\chosen\Chosen::widget([
'model' => $model,
'attribute' => 'geo',
'items' => $arGeo,
'multiple' => true,
]);?>
<?php Html::error($model,'geo');?>
</div>
How can i do it works?
https://harvesthq.github.io/chosen/options.html#attributes
How added attribute disabled via widget
Why do you set $this->options['unselect'] = null inside init()? It is impossible to set unselect option then. For example, I currently faced a problem with editing many-to-many relations with chosen multiple. I need to set unselect option to send an empty value when no options are selected...
I've tried to use the example code
<?= $form->field($model, 'my_actual_attribute')->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,
],
]);?>
And Google Chrome states that there is an error Uncaught TypeError: Cannot read property '0' of undefined
in chosen.jquery.js
on line #143
I suggest to use this code to register plugin events:
public function registerScript()
{
ChosenBootstrapAsset::register($this->getView());
$clientOptions = Json::encode($this->clientOptions);
$id = $this->options['id'];
$this->getView()->registerJs("jQuery('#$id'){$this->buildEvents()}
.chosen({$clientOptions});");
}
protected function buildEvents()
{
if (!empty($this->clientEvents)) {
$events = [];
foreach ($this->clientEvents as $event => $handle) {
$handle = new JsExpression($handle);
$events[] = "on('{$event}', {$handle})";
}
return '.' . implode('.', $events);
}
return '';
}
And stub (or remove) registerEvents()
Other possible decision is use code above to register only "chosen:ready"
Hi! Can you create at least one version? Its bad to use dev-master in composer.json.
IMHO you shouldn't use '@vendor/nex/yii2-chosen/assets' value for asset source path, especially when you haven't composer package (users (like me) can put your extension in some other directory).
You can override init method and use "$this->sourcepath = dirname(FILE) . DIRECTORY_SEPARATOR . 'assets';" code to fix it. Or just register your extension as a composer package.
ChosenAsset.php
public $sourcePath = '@vendor/bower/chosen';
ChosenBootstrapAsset.php
public $sourcePath = '@vendor/bower/chosen-bootstrap';
You should use alias '@bower' not '@vendor/bower' because at least my composer installed all bower assets under 'vendor/bower/bower-assets'. And this was the problem because your extension was looking into wrong path (vendor/bower/chosen but actual path is vendor/bower/bower-assets/chosen).
Yii2 creates @bower alias automatically when bootstrapping that corresponds to current application.
All my other third-party extensions are also using '@bower' instead of '@vendor/bower'.
I ma unable to install this extension in yii2. composer shows error when i run this command
composer require "nex/yii2-chosen" "*"
Deprecation Notice: The Composer\Package\LinkConstraint\MultiConstraint class is
deprecated, use Composer\Semver\Constraint\MultiConstraint instead. in phar://C
:/ProgramData/ComposerSetup/bin/composer.phar/src/Composer/Package/LinkConstrain
t/MultiConstraint.php:17
Deprecation Notice: The Composer\Package\LinkConstraint\LinkConstraintInterface
interface is deprecated, use Composer\Semver\Constraint\ConstraintInterface inst
ead. in phar://C:/ProgramData/ComposerSetup/bin/composer.phar/src/Composer/Packa
ge/LinkConstraint/LinkConstraintInterface.php:17
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
Your requirements could not be resolved to an installable set of packages.
Problem 1
- The requested package dbtek/chosen-bootstrap could not be found in any version, there may be a typo in the package name.
Problem 2
- The requested package nex/yii2-chosen could not be found in any version, there may be a typo in the package name.
Potential causes:
Read https://getcomposer.org/doc/articles/troubleshooting.md for further common problems.
Installation failed, reverting ./composer.json to its original content.
please help ASAP
i need it in yii2 else show me the process for manual installation of this great extension.
If one has other category name for translations - errors in log
[yii\i18n\PhpMessageSource::loadMessages] The message file for category 'app' does not exist...
because of
$this->clientOptions['placeholder_text_single'] = \Yii::t('app', $this->placeholder ? $this->placeholder : 'Select an option');
$this->clientOptions['placeholder_text_multiple'] = \Yii::t('app', $this->placeholder ? $this->placeholder : 'Select some options');
$this->clientOptions['no_results_text'] = \Yii::t('app', 'No results match');
At least add tip to README that app
message source should be configured to avoid hacking widget code.
Another way - add message source to widget options so one could pass custom message source and add this 3 lines to his translations file.
I have a activeform for update a Video information and it has a category field . I use yii2-chosen for show category. but this video has some default category how can i show them in the other words how can I show selected options in select tag?
<?= $form->field($model, 'tag')->widget( Chosen::className(), [ 'items' => [1 => 'First item', 2 => 'Second item', 3 => 'Third item'], 'multiple' => true, 'clientOptions' => [ 'search_contains' => true, 'single_backstroke_delete' => false, ], ]);?>
for example in this part of code I want to first item
be selected
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.