kl83/yii2-rating-widget

Allows you to set an stars-rating for something or show it.

Installs: 88

Dependents: 0

Suggesters: 0

Security: 0

Stars: 1

Watchers: 3

Forks: 1

Open Issues: 0

Language:JavaScript

Type:yii2-extension

v2.0.1 2018-09-09 09:38 UTC

This package is auto-updated.

Last update: 2024-04-09 22:05:21 UTC


README

Latest Stable Version Total Downloads License

Allows you to set an stars-rating for something or show it.

Installation

The preferred way to install this extension is through composer.

Either run

php composer.phar require kl83/yii2-rating-widget ^2.0

or add

"kl83/yii2-rating-widget": "^2.0"

to the require section of your composer.json file.

Usage

FontAwesome asset is used to display stars. Version 4.7 is in use. If you do not have it in your project, \kl83\widgets\RatingWidgetFaAsset asset must be registered.

\kl83\widgets\RatingWidgetFaAsset::register(\Yii::$app->view);

Input widget

$form->field($model, 'rating')->widget('kl83\widgets\RatingInput', [
    'containerOptions' => ['class' => 'some-class'], // HTML attributes
    'maxRating' => 10, // stars count, default - 5
]);
// Sets 5 stars rating
jQuery('.widget').ratingInput('set', 5);

Display widget

\kl83\widgets\RatingWidget::widget([
    'maxRating' => 10, // stars count, default - 5
    'options' => ['class' => 'some-class'], // HTML attributes
    'value' => 4.5, // highlighted stars count
]);
// Initialize widget
jQuery('.widget').ratingWidget();
// Sets 5 stars rating
jQuery('.widget').ratingWidget('set', 5);

License

MIT License