PHP code example of urichalex / yii2-dadata-widget

1. Go to this page and download the library: Download urichalex/yii2-dadata-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/ */

    

urichalex / yii2-dadata-widget example snippets


'container' => [
    'definitions' => [
        \urichalex\yii2Dadata\DadataWidget::class => [
            'apiKey' => 'my-dadata-api-key',
        ],
    ],
],

use urichalex\yii2Dadata\DadataWidget;

<?= DadataWidget::widget([
    'model' => $model,
    'attribute' => 'inn',
    'apiKey' => 'your apiKey'
]) 

<?= DadataWidget::widget([
    'name' => 'inn',
    'apiKey' => 'your apiKey'
]) 

<?= $form->field($model, 'inn')->widget(DadataWidget::class, [
    'apiKey' => 'your apiKey'
]) 

<?= $form->field($model, 'inn')->widget(DadataWidget::class, [
    'apiKey' => 'your apiKey',
    'customAttributes' => [
        // key - model attribute name or form field name, value - attribute from response from service
        'city' => 'city_with_type',
        
        // Value can be an array
        'house' => [
            'attribute' => 'house_with_type', // Dadata response attribute name (response.data.house_with_type)
            'selector' => '#my_input_id', // Form field selector to write the value to
            'createHiddenField' => true, // create hidden field
            'value' => $someValue, // set hidden field value
            'fieldOptions' => [ // some field html options
                'class' => 'myClassName',
                'data-attribute' => 'value'
            ]
        ],
    ],
])