xref: /webtrees/resources/views/modules/GEDFact_assistant/select-census.phtml (revision fca408422158df832c5a18485ea01e348aebd21a)
1d70512abSGreg Roach<?php
2d70512abSGreg Roach
310e06497SGreg Roachdeclare(strict_types=1);
410e06497SGreg Roach
57c2c99faSGreg Roachuse Fisharebest\Webtrees\Census\CensusPlaceInterface;
6d70512abSGreg Roachuse Fisharebest\Webtrees\Date;
77c2c99faSGreg Roachuse Fisharebest\Webtrees\I18N;
87c2c99faSGreg Roach
97c2c99faSGreg Roach/**
107c2c99faSGreg Roach * @var array<CensusPlaceInterface> $census_places
117c2c99faSGreg Roach */
12d70512abSGreg Roach
13d70512abSGreg Roach?>
14dd6b2bfcSGreg Roach
154b9213b3SGreg Roach<select class="form-select census-selector" aria-label="<?= I18N::translate('Census date and place') ?>" autocomplete="off">
16c3f581d9SGreg Roach    <option value="" disabled="disabled" selected="selected" hidden="hidden"><?= I18N::translate('Census date') ?></option>
17dd6b2bfcSGreg Roach
18dd6b2bfcSGreg Roach    <?php foreach ($census_places as $census_place) : ?>
19d3e191dcSDavid Drury        <optgroup label="<?= $census_place->censusPlace() ?>">
20dd6b2bfcSGreg Roach          <?php foreach ($census_place->allCensusDates() as $census) : ?>
21d4786c66SGreg Roach              <option data-wt-date="<?= $census->censusDate() ?>" data-wt-place="<?= $census->censusPlace() ?>" data-wt-census="<?= get_class($census) ?>">
22dd6b2bfcSGreg Roach                  <?= (new Date($census->censusDate()))->minimumDate()->format('%Y') ?>
23f64490b2SGreg Roach24f64490b2SGreg Roach                  <?= $census->censusPlace() ?>
25dd6b2bfcSGreg Roach              </option>
26dd6b2bfcSGreg Roach          <?php endforeach ?>
27d3e191dcSDavid Drury        </optgroup>
28dd6b2bfcSGreg Roach    <?php endforeach ?>
29dd6b2bfcSGreg Roach</select>
3077b47e31SGreg Roach
3177b47e31SGreg Roach<script>
3277b47e31SGreg Roach  document.querySelectorAll('.census-selector').forEach(function (el) {
3377b47e31SGreg Roach    el.addEventListener('change', function (el) {
3477b47e31SGreg Roach      const select = el.target;
3577b47e31SGreg Roach      const option = select.options[select.selectedIndex];
3677b47e31SGreg Roach      const form = select.closest('form');
3777b47e31SGreg Roach
38*fca40842SGreg Roach      form.querySelector('[id$=CENS-DATE]').value = option.dataset.wtDate;
39*fca40842SGreg Roach      form.querySelector('[id$=CENS-PLAC]').value = option.dataset.wtPlace;
4077b47e31SGreg Roach    });
4177b47e31SGreg Roach  });
4277b47e31SGreg Roach</script>
43