, (*1)
Wrapper for DaData's jQuery plugin, (*2)
Installation
1. Download
The preferred way to install this extension is through composer., (*3)
Run the following command:, (*4)
$ composer require corpsepk/yii2-dadata-suggestions-widget:~0.4
2. Get api key
Register at DaData.ru, and get api key., (*5)
You can setup container definitions if you do not want to enter api key in every widget.
Add following lines to your main configuration file:, (*6)
'container' => [
'definitions' => [
'corpsepk\DaData\SuggestionsWidget' => [
'token' => 'my-dadata-api-key',
],
],
],
Usage
use corpsepk\DaData\SuggestionsWidget;
<?= SuggestionsWidget::widget([
'model' => $model,
'attribute' => 'inn',
'token' => 'your apiKey'
]) ?>
The following example will use the name property instead:, (*7)
<?= SuggestionsWidget::widget([
'name' => 'inn',
'token' => 'your apiKey'
]) ?>
You can also use this widget in an yii\widgets\ActiveForm
using the yii\widgets\ActiveField::widget()
method, for example like this:, (*8)
<?= $form->field($model, 'inn')->widget(SuggestionsWidget::class, [
'token' => 'your apiKey'
]) ?>
Useful links
- DaData - https://dadata.ru
- jQuery plugin - https://github.com/hflabs/suggestions-jquery
- jQuery plugin options - https://confluence.hflabs.ru/pages/viewpage.action?pageId=204669097
- Hints - https://dadata.userecho.com/topics/2090
Testing
$ ./vendor/bin/phpunit