Issues (6)

views/_country-region-row.php (1 issue)

Severity
1
<?php
2
/** @var \tonisormisson\addressform\AddressForm $widget */
3
/** @var  \yii\bootstrap\ActiveForm $form */
4
/** @var  \tonisormisson\addressform\models\Address $model */
5
6
use kartik\depdrop\DepDrop;
7
use kartik\select2\Select2;
8
use yii\helpers\Url;
9
use tonisormisson\addressform\AddressHelper;
10
use yii\helpers\ArrayHelper;
11
12
$country =$widget->getCountry();
13
$countryDisabled = (count($widget->allowedCountries) < 2 and !empty($widget->allowedCountries));
14
?>
15
16
<div class="row">
17
    <div class="col-sm-6">
18
        <?= $form->field($model, 'country')->widget(Select2::class, [
19
            'data' => $widget->getCountryList(),
20
            'options' => [
21
                'multiple' => false,
22
                'placeholder' => $widget->placeHolders['country'],
23
                'disabled' => $countryDisabled,
24
                'value' => $country instanceof \Rinvex\Country\Country ? $country->getIsoAlpha2() : null,
25
                'enableClientValidation' => false,
26
            ],
27
            'pluginOptions'=>[
28
                'placeholder' => $widget->placeHolders['country'],
29
            ],
30
        ]);?>
31
        <?= $countryDisabled ?  $form->field($model, 'country')->hiddenInput(['value'=> $country->getIsoAlpha2()])->label(false) : null ?>
32
    </div>
33
34
    <div class="col-sm-6">
35
    <?php if(is_null($country)):?>
36
        <?= $form->field($model, 'state')->widget(DepDrop::class, [
37
            'type'=>DepDrop::TYPE_SELECT2,
38
            'select2Options'=>['pluginOptions'=>['allowClear'=>true]],
39
            'pluginOptions'=>[
40
                'placeholder' => $widget->placeHolders['state'],
41
                'depends'=>[$widget->fieldIdPrefix . 'country'],
42
                'url' => Url::toRoute(['/addressform/query/regions']),
43
                'loadingText' => Yii::t("addressform", "Loading") . "...",
44
                'value' => !is_null($country) ? (new AddressHelper())->formatList($country->getDivisions()) : [],
0 ignored issues
show
The condition is_null($country) is always true.
Loading history...
45
            ],
46
        ]);?>
47
    <?php else:?>
48
        <?= $form->field($model, 'state')->widget(Select2::class, [
49
            'data'=>  ArrayHelper::map((new AddressHelper())->formatList($country->getDivisions()),'id', 'name'),
50
            'options' => [
51
                'placeholder' => $widget->placeHolders['state'],
52
            ],
53
        ]);?>
54
    <?php endif;?>
55
    </div>
56
</div>
57