Rating input is a widget for yii2 framework to render a input for rating.
src/ contains source code of widget
src/assets contains assets definition
src/views contains view files
The minimum requirement by this project template that your Web server supports PHP 5.6.0.
If you do not have Composer, you may install it by following the instructions at getcomposer.org.
You can then install this widget using the following command:
composer require caio-brendo/rating-input
If you have a model, you can use the following code:
<?php
use yii\widgets\ActiveForm;
use caiobrendo\Rating;
$form = ActiveForm::begin(['id' => 'rating-form']); ?>
<div class="row">
<div class="col-md-12">
<?= $form->field($model, 'rating')->widget(Rating::class) ?>
</div>
</div>
ActiveForm::end();
If you don't have a model, you can use the following code:
<?php
use caiobrendo\Rating;
?>
<div class="row">
<div class="col-md-12">
<?= Rating::widget([
'name' => 'rating',
'id' => 'rating-id'
])?>
</div>
</div>
$('.input-rating').on('beforeChange', (event) => {
console.log('beforeChange', event);
})
$('.input-rating').on('afterChange', (event) => {
console.log('afterChange', event);
})
The widget supports all parameters that one would pass for any Yii Input Widget. The additional parameter settings specially available for the rating input widget configuration are:
- model: The model for rendering input.
- attribute: The attribute for rendering input.
- value: The initial or actual value of the rating.
- name: The name of the entry. This is used for modelless widget.
- qtdStar: Star quantity to be selected;
- starHeight: Height for star. Must be a valid css height.
- starSpace: Space between the stars. Must be a valid css.