_form.php
2.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
<?php
use yii\helpers\Html;
use yii\widgets\ActiveForm;
use artbox\core\widgets\LanguageForm;
/* @var $this yii\web\View */
/* @var $model artbox\stock\models\City */
/* @var $form yii\widgets\ActiveForm */
/* @var $modelLangs artbox\stock\models\CityLang */
\artbox\stock\assets\StockAsset::register($this);
\artbox\stock\assets\MapAsset::register($this);
?>
<div class="city-form">
<?php $form = ActiveForm::begin(); ?>
<?= LanguageForm::widget(
[
'modelLangs' => $modelLangs,
'formView' => '@artbox/stock/views/city/_form_language',
'form' => $form,
]
) ?>
<?= $form->field($model, 'coordsArr[lat]')
->textInput(
[
'value' => ( isset($model->coordsArr[ 'lat' ]) ) ? $model->coordsArr[ 'lat' ] : '',
'id' => 'lat',
'size' => 10,
]
)
->label(false); ?>
<?= $form->field($model, 'coordsArr[lng]')
->textInput(
[
'value' => ( isset($model->coordsArr[ 'lng' ]) ) ? $model->coordsArr[ 'lng' ] : '',
'id' => 'lng',
'size' => 10,
]
)
->label(false); ?>
<?= $form->field($model, 'sort')
->textInput() ?>
<?= $form->field($model, 'status')
->checkbox() ?>
<div class="form-group">
<?= Html::submitButton(
$model->isNewRecord ? \Yii::t('stock', 'Create') : \Yii::t('stock', 'Update'),
[ 'class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary' ]
) ?>
</div>
<?php ActiveForm::end(); ?>
</div>
<script>
window.onload = function() {
$(document)
.on('blur', '#city_title', function() {
var address = $("#city_title")
.val();
console.log(address);
var geocoder = new google.maps.Geocoder();
geocoder.geocode({'address': address}, function(results, status) {
console.log(status);
if (status == google.maps.GeocoderStatus.OK) {
$("#lat")
.val(results[ 0 ].geometry.location.lat());
$("#lng")
.val(results[ 0 ].geometry.location.lng());
} else {
alert("Geocode was not successful for the following reason: " + status);
}
});
});
}
</script>