PHP code example of raoul2000 / yii2-twbsmaxlength-widget

1. Go to this page and download the library: Download raoul2000/yii2-twbsmaxlength-widget library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

raoul2000 / yii2-twbsmaxlength-widget example snippets


<input type="text" class="form-control" id="txtinput1" name="xyz" maxlength="20" />


	raoul2000\widget\twbsmaxlength\TwbsMaxlength::widget(['selector' => '#txtinput1']);

 
	use raoul2000\widget\twbsmaxlength\TwbsMaxlength;
	
	$form = ActiveForm::begin(); 

	echo $form->field($model, 'name')
		->textInput(['maxlength' => true])		
		->widget(TwbsMaxlength::className());

	ActiveForm::end();

 
	use raoul2000\widget\twbsmaxlength\TwbsMaxlength;
	
	$form = ActiveForm::begin(); 

	echo $form->field($model, 'name')
		->textInput(['maxlength' => true])		
		->widget(TwbsMaxlength::className(),['type' => TwbsMaxlength::INPUT_TEXTAREA]);

	ActiveForm::end();

class ContactForm extends Model
{
    public $subject;
    
    /**
     * @return array the validation rules.
     */
    public function rules()
    {
        return [
        	['subject','string', 'length'=> [4,10]],
        ];
    }
    // ....

 
	use raoul2000\widget\twbsmaxlength\TwbsMaxlength;
	
	$form = ActiveForm::begin(); 

	echo $form->field($model, 'subject')->widget(TwbsMaxlength::className());

	ActiveForm::end();


  use raoul2000\widget\twbsmaxlength\TwbsMaxlength;
  
  $form = ActiveForm::begin(); 
  
  echo $form->field($model, 'body')
  	->textinput(['maxlength' => true])
  	->widget(
      TwbsMaxlength::className(), 
      [
          'clientOptions' => [
              'threshold'         => 10,
              'preText'           => 'You have ',
              'separator'         => ' of ',
              'postText'          => ' chars remaining.',
              'warningClass'      => "label label-success",
              'limitReachedClass' => "label label-danger"
      ]
  ]);
  
  ActiveForm::end();

 
    use raoul2000\widget\twbsmaxlength\TwbsMaxlength;
    
	$form = ActiveForm::begin(); 

	echo $form->field($model, 'body')
		->textinput(['maxlength' => true])
		->widget(
			TwbsMaxlength::className(),
			[
	    		'type' => TwbsMaxlength::INPUT_TEXTAREA
	    	]
	    );

	ActiveForm::end();


  use raoul2000\widget\twbsmaxlength\TwbsMaxlength;
  
  $form = ActiveForm::begin(); 
  
  echo $form->field($model, 'body')
  	->textinput(['maxlength' => true])
  	->widget(
  		TwbsMaxlength::className(), 
      	[
        	'clientOptions' => [ 'threshold' => 10]
      	]
	);
  
  ActiveForm::end();

 
    use raoul2000\widget\twbsmaxlength\TwbsMaxlength;
    
	$form = ActiveForm::begin(); 

	echo $form->field($model, 'subject')
		->textinput(['maxlength' => true])
		->widget(
			TwbsMaxlength::className(),
			[
    			'thresholdPolicy' => TwbsMaxlength::THRESHOLD_THREE_QUARTERS,
    		]
    	);

	ActiveForm::end();

php composer.phar