This plugin integrates by default with Twitter bootstrap using badges to display the maximum lenght of the field where the user is inserting text. Uses the HTML5 attribute "maxlength" to work.

Overview

Bootstrap MaxLength Build Status

This plugin integrates by default with Twitter bootstrap using badges to display the maximum length of the field where the user is inserting text. This plugin uses the HTML5 attribute "maxlength" to work.

The indicator badge shows up on focusing on the element, and disappears when the focus is lost.

Configurable options

  • alwaysShow: if true the threshold will be ignored and the remaining length indication will be always showing up while typing or on focus on the input. Default: false.
  • threshold: this is a number indicating how many chars are left to start displaying the indications. Default: 0.
  • warningClass: it's the class of the element with the indicator. Default is small form-text text-muted but can be changed to anything you'd like.
  • limitReachedClass: it's the class the element gets when the limit is reached. Default is small form-text text-danger and can be changed.
  • limitExceededClass: it's the class that the element gets when the limit is exceeded. The default is '' In this case, the limitReachedClass setting is used.
  • separator: represents the separator between the number of typed chars and total number of available chars. Default is /.
  • preText: is a string of text that can be outputted in front of the indicator. preText is empty by default.
  • postText: is a string outputted after the indicator. postText is empty by default.
  • showMaxLength: if false, will display just the number of typed characters, e.g. will not display the max length. Default: true.
  • showCharsTyped: if false, will display just the remaining length, e.g. will display remaining length instead of number of typed characters. Default: true.
  • appendToParent: appends the maxlength indicator badge to the parent of the input rather than to the body. Default: false.
  • message: an alternative way to provide the message text, i.e. 'You have typed %charsTyped% chars, %charsRemaining% of %charsTotal% remaining'. %charsTyped%, %charsRemaining% and %charsTotal% will be replaced by the actual values. This overrides the options separator, preText, postText and showMaxLength. Alternatively you may supply a function that the current text and max length and returns the string to be displayed. For example, function(currentText, maxLength) { return '' + Math.ceil(currentText.length / 160) + ' SMS Message(s)'; }
  • utf8: if true the input will count using utf8 bytesize/encoding. For example: the '£' character is counted as two characters. Default: false.
  • showOnReady: shows the badge as soon as it is added to the page, similar to alwaysShow. Default: false.
  • twoCharLinebreak: count linebreak as 2 characters to match IE/Chrome textarea validation. Default: true.
  • customMaxAttribute: String -- allows a custom attribute to display indicator without triggering native maxlength behaviour. Ignored if value greater than a native maxlength attribute. customMaxClass settings gets added when exceeded to allow user to implement form validation. Default is null.
  • customMaxClass: Set the class to be added with 'customMaxAttribute'. The default is 'overmax'.
  • validate: If the browser doesn't support the maxlength attribute, attempt to type more than the indicated chars, will be prevented. Default: false.
  • allowOverMax: Will allow the input to be over the customMaxLength. Useful in soft max situations. Default false.
  • zIndex: Will set the counter z-elevation. Useful to fix elevation in modals or dialogs. Default 1099.
  • placement: Is a string, object, or function, to define where to output the counter.
    • Possible string values are: bottom, left, top, right, bottom-right, top-right, top-left, bottom-left and centered-right. Are also available : bottom-right-inside (default option, as in Google's Material Design), top-right-inside, top-left-inside and bottom-left-inside.
    • Custom placements can be passed as an object, with keys top, right, bottom, left, and position. These are passed to $.fn.css.
    • A custom function may also be passed. This method is invoked with the {$element} Current Input, the {$element} MaxLength Indicator, and the Current Input's Position {bottom height left right top width}.

Events

  • maxlength.reposition on an input element triggers re-placing of its indicator. Useful if textareas are resized by an external trigger.
  • maxlength.shown is triggered when the indicator is displayed.
  • maxlength.hidden is triggered when the indicator is removed from view.

Examples

Basic implementation:

$('[maxlength]').maxlength();

Change the threshold value:

$('input.className').maxlength({
    threshold: 20
});

An example with some of the configurable options:

$('input.className').maxlength({
    alwaysShow: true,
    threshold: 10,
    warningClass: "label label-info",
    limitReachedClass: "label label-warning",
    placement: 'top',
    preText: 'used ',
    separator: ' of ',
    postText: ' chars.'
});

The same example using the message option:

$('input.className').maxlength({
    alwaysShow: true,
    threshold: 10,
    warningClass: "label label-info",
    limitReachedClass: "label label-warning",
    placement: 'top',
    message: 'used %charsTyped% of %charsTotal% chars.'
});

An example allowing user to enter over max characters. NOTE: you cannot have the maxlength attribute on the input element. You will need to provide the customMaxAttribute attribute

Sample HTML element:

<textarea class="form-control" id="xyz" name="xyz" maxlength="10"></textarea>
// Setup maxlength
$('.form-control').maxlength({
	alwaysShow: true,
	validate: false,
	allowOverMax: true,
    customMaxAttribute: "90"
});

// validate form before submit
$('form').on('submit', function (e) {
	$('.form-control').each(
		function () {
			if ($(this).hasClass('overmax')) {
				alert('prevent submit here');
				e.preventDefault();
				return false;
			}
		}
	);
});

An example of triggering a maxlength.reposition event whenever an external autosize plugin resizes a textarea:

$('textarea').on('autosize:resized', function() {
    $(this).trigger('maxlength.reposition');
});
Comments
  • MinLenght

    MinLenght

    Hi, I was wondering if you are open to adding a "minLenght" warning to the plugin (I think it doesn't support this already). Just a warning, no validation; for example, if the input length is less than N then show the widget label in red or yellow, and if the input length is longer or equal than N then show the widget label in green.

    opened by lpalomo 12
  • TypeError: maxLengthIndicator is undefined

    TypeError: maxLengthIndicator is undefined

    Sometimes I get this error and I have absolutely no clue where it is coming from. I think it could have to do that some of my form fields are hidden, but I can not determine any pattern (I don't get it always on the same page and same code).

    TypeError: maxLengthIndicator is undefined
    outerWidth = maxLengthIndicator.outerWidth(),
    
    opened by dhardtke 9
  • Not hidden counter

    Not hidden counter

    If the 'always Show' is setted to 'false' (default). It is not shown the counter.

    If the 'alwaysShow' is setted to 'true'. The display does not hide in the 'blur' event.

    opened by newerton 8
  • Can't overwrite bootstrap css styles

    Can't overwrite bootstrap css styles

    I have a bootstrap theme that sits on top of the framework. Problem is that the theme is being ignored. It's load the styling for the default bootstrap labels. I've changed the colors, font and padding on my theme label classes. If I insert a label right after the input it is rendered properly. Any ideas? DOM loading issue perhaps?

    opened by cardeo 8
  • Issue when apply this plugin in a dialog with

    Issue when apply this plugin in a dialog with "position:fixed" and then user scrolls the page.

    In my case, I am using bootstrap modal dialog for example, if I have a long page, even with a modal dialog opening, I can still scroll the page body behind.

    Then, we will see the character indicator is scrolling along with page body because it is using "position:absolute" for positioning. please see screen shot below.

    snip20140211_1

    To solve this issue, I did two things together, one thing is the issue #45 which I raised for self protection.

    Then, based on #45 , I changed my outside code to listen to the scroll event, when first scroll event happening, I saved the current focused element and call his "blur" event to destroy the label, then, after scroll complete, I called the element with "focus" event to recreate the label, then the new label will take the right position for sure.

    However, since in #45 with isolated context, you choose to reuse existing label which means the label's position will not change, thus, that solution can't be used along with this issue.

    Anyway, a proposed solution might be:

    1. better plugin internally listen to scroll event, when scroll event starts, hide/destroy the label
    2. when scroll events complete, re-calculate the position and then show/new the label.

    Similar code like below

        function HandlingScrolledEvent() {
             // show/new the label
        }
    
        var timerHandle;
        function throttlingScrollEvents() {
            if(timerHandle) {
                window.clearTimeout(timerHandle);
                timerHandle = null;
            }
    
           // hide/destroy existing label
            timerHandle = window.setTimeout(HandlingScrolledEvent, 500);
        }
    
        //listen to global scroll event
        $(window).scroll(throttlingScrollEvents);
    
    opened by realdah 8
  • pasted text in can cause it to go over the max length

    pasted text in can cause it to go over the max length

    We have noticed that sometimes when you paste text into the the text area it will go over the length by a few characters. It will show for example "603 of 600" and if you delete the 3 characters it will again enforce the limit. While we have not been able to reproduce it consistently it has been experienced by several people on our team.

    opened by drewB 8
  •  Incorrect file name length calculation

    Incorrect file name length calculation

    When I tested, I found that there was a calculation error in the file name of the uploaded file. Here is the link I tested in jsfiddle jsfiddle link 2020-02-21_141826

    <input type="text" id="txt_report_title" name="report_title" maxlength="150" value="20200221_DRAMeXchange--Datacenter Demand Gradually Improves in 4Q19, with Three Giants to Enjoy Continual Growth of 8.8% in Server Memory Revenue.pdf" >
     <br> <br> <br> <br> <br> <br>
     <!--  filename = "20200221_DRAMeXchange--Datacenter Demand Gradually Improves in 4Q19, with Three Giants to Enjoy Continual Growth of 8.8% in Server Memory Revenue.pdf"-->
     <input type="file" id="file_report" name="report_title" maxlength="150"  >
    
    $('input#txt_report_title').maxlength();
    $('input#file_report').maxlength({
      alwaysShow: true
      
    });
    
    opened by nick322 6
  • got error when resize window

    got error when resize window

    I am not sure it's a bug or my my failt, when resizing window, error waw shown like below "Uncaught TypeError: Cannot call method 'outerWidth' of undefined "

    if I focus the input at first, resizing the window will not show this error.

    So, at line 276 of source file, I added below

    if(maxLengthIndicator === undefined) return;

    the error disappeared.

    opened by daruma8 6
  • input returning as NaN

    input returning as NaN

    Hello, I am having an issue where the input is continuously returning "NaN" I have been diving into the source and trying to debug what is actually happening and I am stuck. Here is the setup I have in my main script:

        $('textarea#charCount').maxlength({
            alwaysShow: true,
            threshold: 140,
            warningClass: "label label-info",
            limitReachedClass: "label label-warning",
            placement: 'bottom-right',
            preText: 'used ',
            separator: ' of ',
            postText: ' chars.'
        });
    
    opened by brianputz 6
  • Allow user to exceed maxlength

    Allow user to exceed maxlength

    Add option to pass in custom attribute to allow user to exceed maxlength. Form Validation is handled by user using 'overmax' class that is added when maxlength is exceeded. Code example added to readme file.

    opened by ashleyglee 5
  • Indicator won’t hide on blur when `alwaysShow`

    Indicator won’t hide on blur when `alwaysShow`

    alwaysShow is meant to show the indicator as soon as the input gets focus, but that shouldn’t disable the indicator from hiding on blur. This closes #124

    opened by caravinci 4
  • Bump terser from 4.6.13 to 4.8.1

    Bump terser from 4.6.13 to 4.8.1

    Bumps terser from 4.6.13 to 4.8.1.

    Changelog

    Sourced from terser's changelog.

    v4.8.1 (backport)

    • Security fix for RegExps that should not be evaluated (regexp DDOS)

    v4.8.0

    • Support for numeric separators (million = 1_000_000) was added.
    • Assigning properties to a class is now assumed to be pure.
    • Fixed bug where yield wasn't considered a valid property key in generators.

    v4.7.0

    • A bug was fixed where an arrow function would have the wrong size
    • arguments object is now considered safe to retrieve properties from (useful for length, or 0) even when pure_getters is not set.
    • Fixed erroneous const declarations without value (which is invalid) in some corner cases when using collapse_vars.
    Commits

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    • @dependabot use these labels will set the current labels as the default for future PRs for this repo and language
    • @dependabot use these reviewers will set the current reviewers as the default for future PRs for this repo and language
    • @dependabot use these assignees will set the current assignees as the default for future PRs for this repo and language
    • @dependabot use this milestone will set the current milestone as the default for future PRs for this repo and language

    You can disable automated security fix PRs for this repo from the Security Alerts page.

    dependencies 
    opened by dependabot[bot] 0
  • Bump minimist from 1.2.5 to 1.2.6

    Bump minimist from 1.2.5 to 1.2.6

    Bumps minimist from 1.2.5 to 1.2.6.

    Commits

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    • @dependabot use these labels will set the current labels as the default for future PRs for this repo and language
    • @dependabot use these reviewers will set the current reviewers as the default for future PRs for this repo and language
    • @dependabot use these assignees will set the current assignees as the default for future PRs for this repo and language
    • @dependabot use this milestone will set the current milestone as the default for future PRs for this repo and language

    You can disable automated security fix PRs for this repo from the Security Alerts page.

    dependencies 
    opened by dependabot[bot] 0
  • Bump ajv from 6.12.2 to 6.12.6

    Bump ajv from 6.12.2 to 6.12.6

    Bumps ajv from 6.12.2 to 6.12.6.

    Release notes

    Sourced from ajv's releases.

    v6.12.6

    Fix performance issue of "url" format.

    v6.12.5

    Fix uri scheme validation (@​ChALkeR). Fix boolean schemas with strictKeywords option (#1270)

    v6.12.4

    Fix: coercion of one-item arrays to scalar that should fail validation (failing example).

    v6.12.3

    Pass schema object to processCode function Option for strictNumbers (@​issacgerges, #1128) Fixed vulnerability related to untrusted schemas (CVE-2020-15366)

    Commits
    • fe59143 6.12.6
    • d580d3e Merge pull request #1298 from ajv-validator/fix-url
    • fd36389 fix: regular expression for "url" format
    • 490e34c docs: link to v7-beta branch
    • 9cd93a1 docs: note about v7 in readme
    • 877d286 Merge pull request #1262 from b4h0-c4t/refactor-opt-object-type
    • f1c8e45 6.12.5
    • 764035e Merge branch 'ChALkeR-chalker/fix-comma'
    • 3798160 Merge branch 'chalker/fix-comma' of git://github.com/ChALkeR/ajv into ChALkeR...
    • a3c7eba Merge branch 'refactor-opt-object-type' of github.com:b4h0-c4t/ajv into refac...
    • Additional commits viewable in compare view

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    • @dependabot use these labels will set the current labels as the default for future PRs for this repo and language
    • @dependabot use these reviewers will set the current reviewers as the default for future PRs for this repo and language
    • @dependabot use these assignees will set the current assignees as the default for future PRs for this repo and language
    • @dependabot use this milestone will set the current milestone as the default for future PRs for this repo and language

    You can disable automated security fix PRs for this repo from the Security Alerts page.

    dependencies 
    opened by dependabot[bot] 0
  • Support Bootstrap 5

    Support Bootstrap 5

    This pull request will:

    • move qunit to dev dependencies
    • move Bootstrap to peer dependencies
    • allow usage of Bootstrap ^5.0.0
    • allow usage of jQuery ^3.6.0
    opened by MaSpeng 0
  • the hyphenation problem

    the hyphenation problem

    the problem with hyphenation, if we reach the limit, leave 1 character to the maximum number and make a hyphen, then we jump above the allowed limit.

    sorry for my english, see the screenshots

    2021-03-23_140034 2021-03-23_140049

    opened by QaaDee 0
  • allowOverMax is NOT working

    allowOverMax is NOT working

    This is the only reference in code: if (options.customMaxAttribute && !options.allowOverMax) { var custom = currentInput.attr(options.customMaxAttribute); if (!max || custom < max) { max = custom; } } It only replace the maxlength attribute for the custom attribute name. I think that the usefull thing is that the maxlength is only informative when you set allowOverMax to true.

    opened by SashkaDev 2
A jquery plugin to determine when a user has stopped typing in a text field.

The official home for the TypeWatch jQuery plugin. TypeWatch calls a function when a user has typed text in an input, textarea and changes in div from

Denny Ferrassoli 221 Nov 3, 2022
This is a project based on a game Leaderboard. You can interact with an API inserting your user name and score. Built with HTML, CSS, JavaScript and WEBPACK

Leaderboard: Leaderboard project - Microverse Acces link Check the live version here Built With HTML CSS JavaScript VScode Webpack GitFlow Quick view

Vitor Guedes Madeira 11 Oct 8, 2022
Twitter Text Libraries. This code is used at Twitter to tokenize and parse text to meet the expectations for what can be used on the platform.

twitter-text This repository is a collection of libraries and conformance tests to standardize parsing of Tweet text. It synchronizes development, tes

Twitter 2.9k Jan 8, 2023
A Jquery plugin that allows user to enter multiple emails using one input field

multi-emails A Jquery plugin that allows user to enter multiple emails using one input field Usage $("...").multiEmails() Options color textColor font

null 1 Aug 26, 2022
this is a single-page web application. we built a book website where the user can add , remove and display books. we used modules to implement these functionalities. also, we used the Date class to display the date and time.

Awsome Books In this Project, we have built A Books websites. Built With ?? HTML CSS javascript Git & Github Live Demo Here you can find the live Demo

Nedjwa Bouraiou 10 Aug 3, 2022
Extends Bootstrap Tooltips and Popovers by adding custom classes. Available for Bootstrap 3 and Bootstrap 4.

Bootstrap Tooltip Custom Class Extends Bootstrap Tooltips and Popovers by adding custom classes. Available for Bootstrap 3 and Bootstrap 4. Define you

Andrei Victor Bulearca 14 Feb 10, 2022
A simple Form Validation Utility for Bootstrap 3, Bootstrap 4, and Bootstrap 5 for Humans.

bootstrap-validate A simple Form Validation Utility for Bootstrap 3, Bootstrap 4, and Bootstrap 5 for Humans. ?? Support us with Developer Merchandise

null 138 Jan 2, 2023
Easily publish notes to the web This plugin integrates with obsius.site to publish markdown notes on the web.

Obsius Publish Easily publish notes to the web This plugin integrates with obsius.site to publish markdown notes on the web. Limitations The type of c

Jon Grythe Stødle 66 Dec 20, 2022
Bootstrap5-tags - Replace select[multiple] with nices badges

Tags for Bootstrap 4/5 How to use An ES6 native replacement for select using standards Bootstrap 5 (and 4) styles. No additional CSS needed! Supports

Thomas Portelange 75 Jan 9, 2023
Make use of your favicon with badges, images or videos

favico.js More info here. Author Miroslav Magda Version 0.3.9 Contributors: Serge Barysiuk, pissflaps, Yaroslav Yakovlev, LoicMahieu, Renan Gonçalves,

Miroslav Magda 8.7k Dec 21, 2022
💬 A Twitch (BTTV and FFZ) emotes and badges parser - built with tmi.js in mind

?? A Twitch (BTTV and FFZ) emotes and badges parser - built with tmi.js in mind

Lucas Fernandes 8 Sep 2, 2022
Useful GitHub Badges and based on serverless! 🚀

serverless-github-badges This project is inspired by puf17640/git-badges, but built with the serverless stack: Cloudflare Workers and Cloudflare Worke

Zhou Zhiqiang 38 Dec 20, 2022
Fast and lightweight dependency-free vanilla JavaScript polyfill for native lazy loading / the awesome loading='lazy'-attribute.

loading="lazy" attribute polyfill Fast and lightweight vanilla JavaScript polyfill for native lazy loading, meaning the behaviour to load elements rig

Maximilian Franzke 571 Dec 30, 2022
A jQuery plug-in to notify you of CSS, Attribute or Property changes in an element

selectWatch.js jQuery plug-in gives an opportunity to monitor changes of DOM element's CSS styles, attributes, properties, input element or select ele

Fatih Kazancı 3 Oct 28, 2022
This simple extension can automatically load NBN availability information for properties on realestate.com.au & domain.com.au including technology type, maximum line speed, and co-existance status if available.

NBN Availability Check Chrome Extension This simple extension can automatically load NBN availability information for properties on realestate.com.au

Luke Prior 17 Aug 17, 2022
Calculates maximum composite SLA for a list of sequentially provided cloud services or your custom-defined services.

SlaMax Calculates maximum composite SLA for a list of sequentially provided cloud services or your custom-defined services. Here are a few use-cases y

Mikael Vesavuori 4 Sep 19, 2022
Android ROM device support and bringup tool, designed for maximum automation and speed.

adevtool Android ROM device support and bringup tool, designed for maximum automation and speed. Features This tool automates the following tasks for

Danny Lin 186 Dec 21, 2022
A server reimplementation for Wangan Midnight Maximum Tune 6.

Bayshore Wangan Midnight Maximum Tune 6 server reimplementation written in TypeScript Credits This software is part of Project Asakura. At this time,

Project朝倉 20 Dec 23, 2022
Custom alert box using javaScript and css. This plugin will provide the functionality to customize the default JavaScript alert box.

customAlertBoxPlugin Custom Alert Box Plugin Using JavaScript and CSS Author: Suraj Aswal Must Include CSS Code/Default Custom Alert Box Class: /* mus

Suraj Aswal 17 Sep 10, 2022