Documentation v8.1.1

Preview Downloads Purchase

Overview

Bootstrap Maxlength is a visual feedback indicator for the maxlength attribute. For more info please visit the plugin's Homeor Github Repo.

Usage

Bootstrap Maxlength's Javascript files are bundled in the global plugin bundles and globally included in all pages. However, the maxlength functionality requires a manual Javascript initialization.
<script src="assets/plugins/global/plugins.bundle.js"></script>

Basic Example

Basic example of a simple input with the maxlengthHTML attribute to control the total number of characters allowed.
The badge will show up by default when the remaining chars are 10 or less
$('#kt_docs_maxlength_basic').maxlength({
    warningClass: "badge badge-warning",
    limitReachedClass: "badge badge-success"
});
<label class="form-label">Basic example</label>
<input type="text" class="form-control" id="kt_docs_maxlength_basic" maxlength="10" />
<span class="fs-6 text-muted">The badge will show up by default when the remaining chars are 3 or less</span>

Threshold

An example of Bootstrap Maxlength with a treshold option. The thresholdoption is to set the minimum number of characters that will display the badge.
Set threshold value to show there are 20 chars or less left
$('#kt_docs_maxlength_threshold').maxlength({
    threshold: 20,
    warningClass: "badge badge-primary",
    limitReachedClass: "badge badge-success"
});
<label class="form-label">Threshold example</label>
<input type="text" class="form-control" id="kt_docs_maxlength_threshold" maxlength="25" />
<span class="fs-6 text-muted">Set threshold value to show there are 20 chars or less left</span>

Always Show

An example of Bootstrap Maxlength with an always show option. Add alwaysShow: truein the Javascript.
Show the counter on input focus
$('#kt_docs_maxlength_always_show').maxlength({
    alwaysShow: true,
    threshold: 20,
    warningClass: "badge badge-primary",
    limitReachedClass: "badge badge-success"
});
<label class="form-label">Threshold example</label>
<input type="text" class="form-control" id="kt_docs_maxlength_always_show" maxlength="20" />
<span class="fs-6 text-muted">Show the counter on input focus</span>

Custom Text

An example of Bootstrap Maxlength with some custom text in the badge. Please refer to the code sample below for the JS options.
Display custom text on input focus
$('#kt_docs_maxlength_custom_text').maxlength({
    threshold: 20,
    warningClass: "badge badge-danger",
    limitReachedClass: "badge badge-success",
    separator: ' of ',
    preText: 'You have ',
    postText: ' chars remaining.',
    validate: true
});
<label class="form-label">Custom text example</label>
<input type="text" class="form-control" id="kt_docs_maxlength_custom_text" maxlength="20" />
<span class="fs-6 text-muted">Display custom text on input focus</span>

Textarea

Bootstrap Maxlength can also be applied to textarea.
Bootstrap maxlength supports textarea as well as inputs
$('#kt_docs_maxlength_textarea').maxlength({
    warningClass: "badge badge-primary",
    limitReachedClass: "badge badge-success"
});
<label class="form-label">Textarea example</label>
<textarea class="form-control" id="kt_docs_maxlength_textarea" maxlength="20" placeholder="" rows="6"></textarea>
<span class="fs-6 text-muted">Bootstrap maxlength supports textarea as well as inputs</span>

Set Position

Here's an example of predefining the badge position, relative to the input.
The field counter can be positioned at the top, bottom, left or right.
$('#kt_docs_maxlength_position_top_left').maxlength({
    placement: 'top-left',
    warningClass: "badge badge-danger",
    limitReachedClass: "badge badge-primary"
});
<label class="form-label">Set Position example</label>
<input type="text" class="form-control" id="kt_docs_maxlength_position_top_left" maxlength="20" />
<input type="text" class="form-control" id="kt_docs_maxlength_position_top_right" maxlength="20" />
<input type="text" class="form-control" id="kt_docs_maxlength_position_bottom_left" maxlength="20" />
<input type="text" class="form-control" id="kt_docs_maxlength_position_bottom_right" maxlength="20" />
<span class="fs-6 text-muted">The field counter can be positioned at the top, bottom, left or right.</span>

Modal Example

Use Date Range Picker within Bootstrap Modal:
$('#kt_docs_maxlength_basic_modal').maxlength({
    warningClass: "badge badge-primary",
    limitReachedClass: "badge badge-success"
});
<!--begin::Modal-->
<div class="modal fade" tabindex="-1" id="kt_modal_1">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title">Modal title</h5>

                <!--begin::Close-->
                <div class="btn btn-icon btn-sm btn-active-light-primary ms-2" data-bs-dismiss="modal" aria-label="Close">
                    <span class="svg-icon svg-icon-2x"></span>
                </div>
                <!--end::Close-->
            </div>

            <div class="modal-body">
                <label class="form-label">Basic example</label>
                <input type="text" class="form-control mb-3" id="kt_docs_maxlength_basic" maxlength="10" />
                <span class="fs-6 text-muted">The badge will show up by default when the remaining chars are 10 or less</span>
            </div>

            <div class="modal-footer">
                <button type="button" class="btn btn-light" data-bs-dismiss="modal">Close</button>
                <button type="button" class="btn btn-primary">Save changes</button>
            </div>
        </div>
    </div>
</div>
<!--end::Modal-->

Demos

Metronic Licenses

License FAQs
Regular License
For single end product used by you or one client
$ 39
Extended License
For single SaaS app with paying users
$ 969
Custom License
Reach us for custom license offers.
Buy Now
Learn & Get Inspired

Support at devs.keenthemes.com

Join our developers community to find answer to your question and help others. FAQs
Get Support
Documentation & Videos
From guides and video tutorials, to live demos and code examples to get started.
Plugins & Components
Check out our 300+ in-house components and customized 3rd-party plugins.
Layout Builder
Build your layout, preview it and export the HTML for server side integration.
Metronic Downloads
Download your prefered framework and demo with one click.
What's New
Latest features and improvements added with our users feedback in mind.