2017 © Pedro Peláez
 

yii2-extension yii2-int-tel-input-widget

Yii2 input widget created on basis of jquery plugin http://jackocnr.com/intl-tel-input.html

image

integready/yii2-int-tel-input-widget

Yii2 input widget created on basis of jquery plugin http://jackocnr.com/intl-tel-input.html

  • Wednesday, March 21, 2018
  • by Stern87
  • Repository
  • 1 Watchers
  • 0 Stars
  • 26 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 5 Versions
  • 0 % Grown

The README.md

Yii2 International telephone numbers - Asset Bundle, Behavior, Validator, Widget

This extension uses 2 libraries:, (*1)

Installation

The preferred way to install this extension is through composer., (*2)

Either run, (*3)

$ php composer.phar require "integready/yii2-intl-tel-input" "~2.0.0"

or add, (*4)

"integready/yii2-intl-tel-input": "~2.0.0"

to the require section of your composer.json file., (*5)

Usage

Using as an ActiveField widget with the preferred countries on the top:, (*6)

use integready\extensions\phoneInput\PhoneInput;

echo $form->field($model, 'phone_number')->widget(PhoneInput::class, [
    'jsOptions' => [
        'preferredCountries' => ['no', 'pl', 'ua'],
    ]
]);

Using as a simple widget with the limited countries list:, (*7)

use integready\extensions\phoneInput\PhoneInput;

echo PhoneInput::widget([
    'name' => 'phone_number',
    'jsOptions' => [
        'allowExtensions' => true,
        'onlyCountries' => ['no', 'pl', 'ua'],
    ]
]);

Using phone validator in a model (validates the correct country code and phone format):, (*8)

namespace frontend\models;

use integready\extensions\phoneInput\PhoneInputValidator;

class Company extends Model
{
    public $phone;

    public function rules()
    {
        return [
            [['phone'], 'string'],
            [['phone'], PhoneInputValidator::class],
        ];
    }
}

or if you need to validate phones of some countries:, (*9)

namespace frontend\models;

use integready\extensions\phoneInput\PhoneInputValidator;

class Company extends Model
{
    public $phone;

    public function rules()
    {
        return [
            [['phone'], 'string'],
            // [['phone'], PhoneInputValidator::className(), 'region' => 'UA'],
            [['phone'], PhoneInputValidator::className(), 'region' => ['PL', 'UA']],
        ];
    }
}

Using phone behavior in a model (auto-formats phone string to the required phone format):, (*10)

namespace frontend\models;

use integready\extensions\phoneInput\PhoneInputBehavior;

class Company extends Model
{
    public $phone;

    public function behaviors()
    {
        return [
            'phoneInput' => PhoneInputBehavior::class,
        ];
    }
}

You can also thanks to this behavior save to database country code of the phone number. Just add your attribute as countryCodeAttribute and it'll be inserted into database with the phone number., (*11)

namespace frontend\models;

use integready\extensions\phoneInput\PhoneInputBehavior;

class Company extends Model
{
    public $phone;
    public $countryCode;

    public function behaviors()
    {
        return [
            [
                'class'                => PhoneInputBehavior::class,
                'countryCodeAttribute' => 'countryCode',
            ],
        ];
    }
}

Note: nationalMode option is very important! In case if you want to manage phone numbers with country/operator code - you have to set nationalMode: false in widget options (for example, PhoneInput::widget(...options, ['jsOptions' => ['nationalMode' => false]]))., (*12)

The Versions

21/03 2018

dev-master

9999999-dev https://github.com/IntegReady/yii2-int-tel-input-widget

Yii2 input widget created on basis of jquery plugin http://jackocnr.com/intl-tel-input.html

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

by IntegReady

helpers extension yii2 widgets

21/03 2018

1.0.2.1

1.0.2.1 https://github.com/IntegReady/yii2-int-tel-input-widget

Yii2 input widget created on basis of jquery plugin http://jackocnr.com/intl-tel-input.html

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

by IntegReady

helpers extension yii2 widgets

21/03 2018

1.0.2

1.0.2.0 https://github.com/IntegReady/yii2-int-tel-input-widget

Yii2 input widget created on basis of jquery plugin http://jackocnr.com/intl-tel-input.html

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

by IntegReady

helpers extension yii2 widgets

25/02 2017

1.0.1

1.0.1.0 https://github.com/IntegReady/yii2-int-tel-input-widget

Yii2 input widget created on basis of jquery plugin http://jackocnr.com/intl-tel-input.html

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

by IntegReady

helpers extension yii2 widgets

14/12 2015

1.0

1.0.0.0

Yii2 input widget created on basis of jquery plugin http://jackocnr.com/intl-tel-input.html

  Sources   Download

BSD-3-Clause

The Requires

 

by Andrey Galyamov

helpers extension yii2 widgets