caio-brendo / rating-input
Componente que renderiza estrelas para seleção, bastante útil para trabalhar com avaliações.
Installs: 3
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Type:yii2-extension
Requires
- yiisoft/yii2: ~2.0.0
- yiisoft/yii2-bootstrap: ~2.0.0
This package is auto-updated.
Last update: 2024-11-11 10:58:34 UTC
README
Rating Input
Rating input is a widget for yii2 framework to render a input for rating.
DIRECTORY STRUCTURE
src/ contains source code of widget
src/assets contains assets definition
src/views contains view files
REQUIREMENTS
The minimum requirement by this project template that your Web server supports PHP 5.6.0.
INSTALLATION
Install via Composer
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
USAGE
With model
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();
Without model
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>
JAVASCRIPT EVENTS
$('.input-rating').on('beforeChange', (event) => { console.log('beforeChange', event); }) $('.input-rating').on('afterChange', (event) => { console.log('afterChange', event); })
SETTINGS
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.