xref: /webtrees/resources/views/modules/GEDFact_assistant/select-census.phtml (revision 4a9a60957058ca2a34e30a0d6f783e1540606590)
1<?php
2
3declare(strict_types=1);
4
5use Fisharebest\Webtrees\Census\CensusPlaceInterface;
6use Fisharebest\Webtrees\Date;
7use Fisharebest\Webtrees\I18N;
8
9/**
10 * @var array<CensusPlaceInterface> $census_places
11 */
12
13?>
14
15<select class="form-select census-selector" aria-label="<?= I18N::translate('Census date and place') ?>" autocomplete="off">
16    <option value="" disabled="disabled" selected="selected" hidden="hidden"><?= I18N::translate('Census date') ?></option>
17
18    <?php foreach ($census_places as $census_place) : ?>
19        <optgroup label="<?= $census_place->censusPlace() ?>">
20          <?php foreach ($census_place->allCensusDates() as $census) : ?>
21              <option data-wt-date="<?= $census->censusDate() ?>" data-wt-place="<?= $census->censusPlace() ?>" data-wt-census="<?= get_class($census) ?>">
22                  <?= (new Date($census->censusDate()))->minimumDate()->format('%Y') ?>
2324                  <?= $census->censusPlace() ?>
25              </option>
26          <?php endforeach ?>
27        </optgroup>
28    <?php endforeach ?>
29</select>
30
31<script>
32  document.querySelectorAll('.census-selector').forEach(function (el) {
33    el.addEventListener('change', function (el) {
34      const select = el.target;
35      const option = select.options[select.selectedIndex];
36      const form = select.closest('form');
37
38      form.querySelector('[id$=CENS\\3a DATE]').value = option.dataset.wtDate;
39      form.querySelector('[id$=CENS\\3a PLAC]').value = option.dataset.wtPlace;
40    });
41  });
42</script>
43