Download the PHP package raoul2000/yii2-twbsmaxlength-widget without Composer

On this page you can find all versions of the php package raoul2000/yii2-twbsmaxlength-widget. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package yii2-twbsmaxlength-widget

yii2-twbsmaxlength-widget

The TwbsMaxlength widget is a wrapper for the great Bootstrap Maxlength plugin, a visual feedback indicator for the maxlength attribute. Have a look to the demo page for more !

Installation

The preferred way to install this extension is through composer.

Either run

or add

to the require section of your composer.json file.

Basic Usage

Using TwbsMaxlength widget is easy. In the example below, we are attaching the "Bootstrap Maxlength" plugin to an input text control, with a maximum length of 20 characters set by the maxlength HTML5 attribute :

The user will not be able to enter more than 20 characters in the text input control. After the 10th character (hard coded default) is entered by the user, a small alert will appear at the bottom of the control.

Remember to use the selector option only when you need to attach the "Bootstrap Maxlength" plugin to an existing HTML input tag (text or textarea).

ActiveForm

Most of the time, a text or textarea input control is produced by an ActiveForm widget. The TwbsMaxlength is of course also able to handle such use case.

The code above only works since Yii2 v2.0.3 which includes a feature to automatically set the maxlength attribute of an ActiveField textInput based on the related string validation rule (Read more...)

To use it with a textarea, simply add the typeconfiguration parameter with value TwbsMaxlength::INPUT_TEXTAREA :

Legacy support

If you are using Yii2 version prior to 2.0.3 no problem : the TwbsMaxlength widget implements the same kind of feature than Yii2 2.0.3. If you don't set the maxlength HTML5 attribute yourself, the widget will search for this value among the validation rules defined for the model's attribute. If the rule string is found and if a maximum length is set, it will be used to inject maxlength into the HTML input element. Otherwise the "Bootstrap Maxlength* plugin will not be enabled.

Let's see that on an example with the famous ContactForm model. We use the StringValidator to define the maximum length of the 'subject' attribute (here it will be set to 10) :

Now, no need to set the maxlength HTML5 attribute because the widget will do it for us. We can simply write :

And that's it ! Take a look to the input tag created and you'll see that the maxlength HTML5 attribute has been set to 10, just like defined in the validation rule of the subject attribute.

Plugin Options

The Bootstrap Maxlength accepts several options to custoomize its behavior. These options can be initialized in the clientOptions array, when configuring the widget.

For more information on the plugin options, please refer to bootstrap-maxlength github page.

Widget Options

textarea

To produce a textarea element instead of the classical text input (produced by default), use the type option when configuring your widget.

Setting the Threshold

The threshold is a numeric value representing the number of characters left before reaching the maxlength limitation. When the threshold is reached, an alert is displayed to the user to inform her/him that the max length is about to be reached. You can set the threshold value option like any other clientOption for the plugin.

TwbsMaxlength provide a way to dynamically calculate the threshold value depending on the max length value. This option name is thresholdPolicy. The TwbsMaxlength widget includes 3 built-in thresholds policies :

In the example below, the alert will be displayed after 3/4 of the total number of character allowed have been entered by the user. So for instance if the "subject' validation rule set the maximum length to be 40, the alert will show up when 30 characters are entered.

Note that the thresholdPolicy is only available when working with ActiveForms.

License

yii2-twbsmaxlength-widget is released under the BSD 3-Clause License. See the bundled LICENSE.md for details.


All versions of yii2-twbsmaxlength-widget with dependencies

PHP Build Version
Package Version
Requires yiisoft/yii2 Version *
bower-asset/bootstrap-maxlength Version *
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package raoul2000/yii2-twbsmaxlength-widget contains the following files

Loading the files please wait ....