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