Skip to main content
https://badge.fury.io/py/django-charsleft-widget.svg https://img.shields.io/pypi/pyversions/django-charsleft-widget.svg https://img.shields.io/pypi/djversions/django-charsleft-widget.svg https://github.com/bashu/django-charsleft-widget/actions/workflows/test.yml/badge.svg

django-charsleft-widget is a custom widget that limits the number of characters that can be entered in a textarea field.

https://raw.githubusercontent.com/bashu/django-charsleft-widget/develop/showcase.gif

Installation

pip install django-charsleft-widget

Setup

Add charsleft_widget to INSTALLED_APPS:

INSTALLED_APPS += (
    'charsleft_widget',
)

and just include charsleft_widget templates

{% include "charsleft_widget/charsleft_widget_css.html" %} {# Before the closing head tag #}
{% include "charsleft_widget/charsleft_widget_js.html" %} {# Before the closing body tag #}

When deploying on production server, don’t forget to run:

python manage.py collectstatic

Usage

All you need now is to import ClearableInput class and override field’s widget, for example:

from django.forms.fields import CharField

from charsleft_widget import CharsLeftArea

class Form(forms.Form):

    field = CharField(max_length=128, widget=CharsLeftArea)

Please see example application. This application is used to manually test the functionalities of this package. This also serves as a good example.

You need Django 5.2 or above to run that.

License

django-charsleft-widget is released under the BSD license.

Changes

1.2.0 (2026-09-08)

  • Dropped the jQuery dependency: charsleft.js is now plain JavaScript with no reliance on window.jQuery or window.django.jQuery. Pages that inject markup after page load (formsets, ajax) now re-bind newly-added .charsleft widgets via window.charsleft(scope) instead of the former $.fn.charsleft jQuery plugin.

1.1.0 (2026-08-14)

  • Added Django 6.0 and 6.1 support, alongside existing Django 5.2 support (fixes #7).

  • Dropped Python < 3.10 support.

  • Fixed charsleft.js: a page without both jQuery and a django global crashed with ReferenceError: django is not defined; typing past maxlength right on an emoji or other astral character split its UTF-16 surrogate pair and corrupted the field; only keyup/change were handled, so paste-via-mouse and IME input didn’t update the count; dynamically-added widgets (formsets, ajax) were never wired up; and the charsleft helper leaked onto window.

  • Fixed USE_JINJA rendering: textarea.jinja lived under templates/, where Django’s Jinja2 backend (APP_DIRS scans each app’s jinja2/ directory) could never find it; moved it to charsleft_widget/jinja2/.

  • Removed charsleft_widget/fields.py, a pre-Django-1.7 maxlength shim superseded by Django core and unused since.

  • locale/ and jinja2/ assets weren’t declared in package-data and were silently missing from built wheels/sdists; added.

  • Increased test coverage to 100%; added tests for Media, a value already over maxlength, and the Jinja2 backend actually being used.

  • Reformatted code and templates, and fixed ruff lint findings.

1.0.0 (2021-11-30)

  • Added Django 3+ support.

  • Dropped Python 2.7 support.

  • Dropped Django 1.10 / 1.11 support.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django_charsleft_widget-1.2.0.tar.gz (11.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_charsleft_widget-1.2.0-py3-none-any.whl (10.9 kB view details)

Uploaded Python 3

File details

Details for the file django_charsleft_widget-1.2.0.tar.gz.

File metadata

  • Download URL: django_charsleft_widget-1.2.0.tar.gz
  • Upload date:
  • Size: 11.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for django_charsleft_widget-1.2.0.tar.gz
Algorithm Hash digest
SHA256 99d3bacc6f21f3ffe7e833cc915972c07ed6019b4cde1357889ec5f486dba2cf
MD5 442abe95ba6bf918d016773f208249bd
BLAKE2b-256 2c9bc6a497106394e493e882278f58075b8b89836a6bf8fb09e8eb86b6cacd2e

See more details on using hashes here.

Provenance

The following attestation bundles were made for django_charsleft_widget-1.2.0.tar.gz:

Publisher: release.yml on bashu/django-charsleft-widget

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file django_charsleft_widget-1.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for django_charsleft_widget-1.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9f10ace6f4d2a597aff477d05102334028bac0adb6eae71f9d13b5cd33773bd6
MD5 bb0dd515a325b0ad9ba1297ef3fdc6b5
BLAKE2b-256 e7a2971bb804f5213674a1b21f4a95516fe6ccb20f77655039ffd66305ee5e50

See more details on using hashes here.

Provenance

The following attestation bundles were made for django_charsleft_widget-1.2.0-py3-none-any.whl:

Publisher: release.yml on bashu/django-charsleft-widget

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

This release

1.2.0 This release

2 files

1.1.0

2 files

1.0.0

2 files

0.1.9

2 files

0.1.8

2 files

0.1.7

2 files

0.1.6

2 files

0.1.5

1 file

0.1.4

1 file

0.1.3

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page