Metadata-Version: 2.4
Name: django-charsleft-widget
Version: 1.1.0
Summary: Custom widget that limits the number of characters that can be entered in a textarea field
Author-email: Basil Shubin <basil.shubin@gmail.com>
License-Expression: BSD-3-Clause
Project-URL: download, https://github.com/bashu/django-charsleft-widget/zipball/master
Project-URL: homepage, https://github.com/bashu/django-charsleft-widget/
Classifier: Development Status :: 5 - Production/Stable
Classifier: Environment :: Web Environment
Classifier: Framework :: Django
Classifier: Framework :: Django :: 5.2
Classifier: Framework :: Django :: 6.0
Classifier: Framework :: Django :: 6.1
Classifier: Intended Audience :: Developers
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Topic :: Internet :: WWW/HTTP
Classifier: Topic :: Internet :: WWW/HTTP :: Dynamic Content
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Requires-Python: >=3.10
Description-Content-Type: text/x-rst
License-File: LICENSE
Requires-Dist: django>=5.2
Dynamic: license-file

django-charsleft-widget
=======================

.. image:: https://badge.fury.io/py/django-charsleft-widget.svg
    :target: https://badge.fury.io/py/django-charsleft-widget

.. image:: https://img.shields.io/pypi/pyversions/django-charsleft-widget.svg
    :target: https://pypi.python.org/pypi/django-charsleft-widget/

.. image:: https://img.shields.io/pypi/djversions/django-charsleft-widget.svg
    :target: https://pypi.python.org/pypi/django-charsleft-widget/

.. image:: https://github.com/bashu/django-charsleft-widget/actions/workflows/test.yml/badge.svg
    :target: https://github.com/bashu/django-charsleft-widget/actions/workflows/test.yml

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

.. image:: https://raw.githubusercontent.com/bashu/django-charsleft-widget/develop/showcase.gif
   :target: https://raw.githubusercontent.com/bashu/django-charsleft-widget/develop/showcase.gif
   :align: center
   :width: 600px

Installation
------------

.. code-block:: bash

    pip install django-charsleft-widget

External dependencies
~~~~~~~~~~~~~~~~~~~~~

* jQuery - this is not included in the package since it is expected
  that in most scenarios this would already be available.

Setup
-----

Add ``charsleft_widget`` to  ``INSTALLED_APPS``:

.. code-block:: python

    INSTALLED_APPS += (
        'charsleft_widget',
    )

and just include ``charsleft_widget`` templates

.. code-block:: html+django

    {% 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:

.. code-block:: shell

    python manage.py collectstatic

Usage
-----

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

.. code-block:: python

    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.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.
