jlorente/yii2-widget-remainingcharacters

Widget to add a remaining character counter to text inputs and textareas

1.0.1 2015-03-17 14:50 UTC

This package is auto-updated.

Last update: 2024-12-10 05:22:11 UTC


README

RemainingCharacters widget is a Yii2 wrapper for the jquery-remaining-characters jQuery plugin Remaining Characters jQuery plugin. This input widget is a replacement for text and textarea inputs. It appends a container with a countdown counter of characters to the input.

Installation

The preferred way to install this extension is through composer. Check the composer.json for this extension's requirements and dependencies.

To install, either run

$ php composer.phar require jlorente/yii2-widget-remainingcharacters "*"

or add

...
    "require": {
        ...
        "jlorente/yii2-widget-remainingcharacters": "*"
    }

to the require section of your composer.json file.

Usage

use jlorente\remainingcharacters\RemainingCharacters;

// 
echo $form->field($model, 'my-textarea')->widget(RemainingCharacters::classname(), [
    'type' => RemainingCharacters::INPUT_TEXTAREA,
    'text' => Yii::t('app', '{n} characters remaining'),
    'label' => [
        'tag' => 'p',
        'id' => 'my-counter',
        'class' => 'counter',
        'invalidClass' => 'error'
    ],
    'options' => [
        'rows' => '3',
        'class' => 'col-md-12',
        'maxlength' => 200,
        'placeholder' => Yii::t('app', 'Write something')
    ]
]);

Where options array are the options for the textarea.

Options

License

Copyright © 2015 José Lorente Martín. Licensed under the MIT license. See LICENSE.txt for details.