coveringType();
if ($coveringType == Geo::COVERING_CITY) {
$form
->text($fieldNameCity, $title, $this->coveringRegion(), false)
->beforeFieldRender(function ($html) { /** @var $this Geo */
return '
'.$html.'
' .
($this->regionData($this->coveringRegion())['title'] ?? '') ;
})
;
return;
}
$form->autocomplete(
$fieldNameCity,
$title,
function ($q) use ($suggest) { /** @var $this Geo */
$suggest['q'] = $q;
$suggest['asArray'] = true;
$data = $this->regionSuggest($suggest);
return $data['response'] ?? [];
},
function ($id) { /** @var $this Geo */
$data = $this->regionSuggest(['id' => $id, 'asArray' => true]);
$data = $data['list'] ?? [];
if (empty($data)) {
return '';
}
$data = reset($data);
return $data['title'] ?? '';
},
$placeholder,
$ac
)
->beforeFieldView(function ($p, $field) use ($form, $fieldNameCity, $fieldNameCountry) { /** @var Autocomplete $field */
$country = $this->defaultCountry();
if (! isset($field->custom['init']['suggest'])) {
$d = $form->_data();
if (! empty($d[ $fieldNameCity ]) && ! empty($d[ $fieldNameCountry ])) {
$country = $d[ $fieldNameCountry ];
}
$field->custom['init']['suggest'] = $this->regionPreSuggest((int)$country, ['json' => false]);
}
if (! isset($field->custom['init']['params']['country_id'])) {
$field->custom['init']['params']['country_id'] = $country;
}
if (! isset($field->custom['init']['onSelect'])) {
$field->custom['init']['onSelect'] = function () { ?>classAdd('j-geo-city-ac-id')
->attr('class', 'j-geo-city-ac-title')
->attr('class', 'j-geo-city-title')
;
if ($coveringType == Geo::COVERING_COUNTRIES) {
$form->select($fieldNameCountry, '', $this->defaultCountry(), function() {
return $this->countriesList();
}, $countryEmpty)
->attr('class', 'j-geo-country-id')
->together($fieldNameCity, ['newLine' => true, 'marginLeft' => 0, 'first' => true])
->jsOnChange(function (){ ?>to($fieldNameCity)
;
}