corpsepk / yii2-dadata-suggestions-widget
DaData Suggestions jQuery widget wrapper
Installs: 30 642
Dependents: 0
Suggesters: 0
Security: 0
Stars: 10
Watchers: 3
Forks: 3
Type:yii2-extension
Requires
- php: >=5.6
- yiisoft/yii2: ~2.0.0
Requires (Dev)
- phpunit/phpunit: ~4.0
- scrutinizer/ocular: ~1.1
This package is auto-updated.
Last update: 2025-03-22 04:08:05 UTC
README
Wrapper for DaData's jQuery plugin
Installation
1. Download
The preferred way to install this extension is through composer.
Run the following command:
$ composer require corpsepk/yii2-dadata-suggestions-widget:~0.4
2. Get api key
Register at DaData.ru, and get api key.
3. Configure (optional)
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:
'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:
<?= 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:
<?= $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