Character Counter plugin screenshot
Dark mode ready
Multilingual support
No v5.x support

Character Counter by Tally Schmeits

Community

A character counter for Text, Textarea and RichEditor fields

Tags: Forms Form Field
Supported versions:
4.x 3.x
Tally Schmeits avatar Author: Tally Schmeits

Package health

Automated checks of this plugin's Composer package

100 / 100
Security 100
Maintenance 100
Ecosystem 100
15 checks
  • Passed: GitHub Actions pinned to SHA
  • Skipped: GitLab CI includes pinned to SHA
  • Passed: Open security advisories
  • Passed: Dependabot PR responsiveness — No open Dependabot PRs.
  • Skipped: Renovate MR responsiveness
  • Passed: Dependabot or Renovate configured
  • Passed: Dependency update cooldown configured
  • Passed: Provides a security policy
  • Passed: Abandoned or archived — No consulted source marks the package abandoned (packagist, github).
  • Passed: Commit and release recency — Active: last commit 1 days ago; last release 117 days ago.
  • Passed: composer.lock not committed by library — composer.lock is absent from the released dist archive.
  • Passed: Dist archive is lean
  • Passed: Current Laravel version supported — Package dependencies resolve together with current Laravel 13.0.
  • Passed: Current PHP version supported — Constraint ^8.2 supports current PHP 8.5.
  • Skipped: Current Symfony version supported
Third-party plugin. This is built by the community, not the Filament team. Filament does not review, endorse, or vet the security of plugins outside the filament/ namespace. Review the source and install at your own risk. Found malware or an unresolved security issue the author won't address? Report it .
Powered by Plumb Last scanned 2 weeks ago

Documentation

Latest Version on Packagist GitHub Tests Action Status Total Downloads

A character counter for the TextInput, Textarea and RichEditor fields of Filament 4 and 5.

example-screenshot.png

#Compatibility

Plugin version Filament Laravel PHP
1.x 3.2 10, 11 8.1 or newer
5.x 4, 5 12, 13 8.2 or newer (8.3 for L13)

#Installation

composer require schmeits/filament-character-counter:"^5.0"

For Filament 3.2, use version ^1.0.

The package ships a small stylesheet that is registered with Filament. After installing or updating, publish Filament's assets as usual:

php artisan filament:assets

#Usage

use Schmeits\FilamentCharacterCounter\Forms\Components\RichEditor;
use Schmeits\FilamentCharacterCounter\Forms\Components\Textarea;
use Schmeits\FilamentCharacterCounter\Forms\Components\TextInput;

TextInput::make('title')
    ->characterLimit(50),

Textarea::make('description')
    ->characterLimit(155),

RichEditor::make('content')
    ->characterLimit(155),

#Soft limit and hard limit

  • characterLimit() is a soft limit: it only drives the counter. The user can type past it; the counter then says how many characters are too many, for example "(12 too many)".
  • maxLength() is a hard limit: the browser stops typing at that length and Laravel validates it. Without a characterLimit(), the counter uses maxLength().
// Counter shows 0 / 50, typing stops at 50.
TextInput::make('title')
    ->maxLength(50),

// Counter warns past 150, typing stops at 200.
TextInput::make('title')
    ->characterLimit(150)
    ->maxLength(200),

Both accept a closure. Without any limit the counter only shows the number of characters.

#Counter inside the field

TextInput and Textarea can show the counter inside the input:

TextInput::make('title')
    ->showInsideControl()
    ->characterLimit(50),

#Hiding the counter

use Filament\Schemas\Components\Utilities\Get;

// Never show the counter on this field
TextInput::make('slug')
    ->showCharacterCounter(false)
    ->characterLimit(100),

// Show it only when another field is on
Textarea::make('bio')
    ->showCharacterCounter(fn (Get $get): bool => (bool) $get('is_public'))
    ->characterLimit(255),

#How characters are counted

The counter counts per character (code point), the same way Laravel's max: rule does, so an emoji counts as one. It follows typing, pasting, autofill and changes made from PHP, such as $set() or resetting the form.

#Accessibility

Going over the limit is shown in words and in bold, not by colour alone, and is announced to screen readers. The input is linked to its counter with aria-describedby.

#Configuration

Publish the config file:

php artisan vendor:publish --tag="filament-character-counter-config"
return [
    // Set to false to leave out the package stylesheet and style the counter yourself.
    'load_css' => true,
];

The counter uses these CSS classes: fi-input-charcounter for the counter and fi-input-charcounter-exceeded when the limit is passed.

#Translations

Publish the translations:

php artisan vendor:publish --tag="filament-character-counter-translations"
return [
    'character_separator' => ' / ',
    'character_label' => 'characters',
    'characters_over' => '(:count too many)',
];

#Upgrading to 5.2

  • The RichEditor is no longer a copy of Filament's view. Filament renders the editor itself and the counter is placed around it, so features such as file attachments and mentions work again. If you published rich-editor.blade.php, delete it and publish again.
  • The CSS class for an exceeded limit changed from warning to fi-input-charcounter-exceeded.
  • The old translation key character_seperator is no longer read. Use character_separator.
  • getShowCharacterCounter() is deprecated in favour of shouldShowCharacterCounter().

#Testing

composer test
composer analyse

#Changelog

Please see CHANGELOG for more information on what has changed recently.

#Contributing

Please see CONTRIBUTING for details.

#Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

#Need help with Filament?

I'm Tally Schmeits, the maintainer of this package. I build and maintain Filament and Laravel applications for clients: new admin panels and business applications, upgrades to Filament 4 and 5, and taking over existing Filament apps. More at schmeits.com/filament-specialist.

#Credits

#License

The MIT License (MIT). Please see License File for more information.