1<?php use Fisharebest\Webtrees\I18N; ?> 2 3<form method="post" action="<?= e(route('create-note-object')) ?>" id="wt-modal-form"> 4 <?= csrf_field() ?> 5 <input type="hidden" name="ged" value="<?= e($tree->name()) ?>"> 6 7 <?= view('modals/header', ['title' => I18N::translate('Create a shared note')]) ?> 8 9 <div class="modal-body"> 10 <?= view('modals/note-object-fields') ?> 11 </div> 12 13 <?= view('modals/footer-save-cancel') ?> 14</form> 15 16<script> 17 // Submit the modal form using AJAX 18 document.getElementById("wt-modal-form").addEventListener("submit", function (event) { 19 event.preventDefault(); 20 let form = event.target; 21 let modal_content = document.querySelector("#wt-ajax-modal .modal-content"); 22 let select = document.getElementById(modal_content.dataset.selectId); 23 24 $.ajax({ 25 url: form.action, 26 type: form.method, 27 data: new FormData(form), 28 async: false, 29 cache: false, 30 contentType: false, 31 processData: false, 32 success: function (data) { 33 if (select) { 34 // If this modal was activated by the "new" button in a select2 35 // edit control, then insert the result and select it. 36 let option = new Option(data.text, data.id, true, true); 37 option.innerHTML = option.innerText; 38 option.innerHTML = data.text; 39 40 $(select) 41 .select2() 42 .empty() 43 .append(option) 44 .trigger("change"); 45 46 $("#wt-ajax-modal").modal("hide"); 47 } else { 48 modal_content.innerHTML = data.html; 49 } 50 }, 51 failure: function (data) { 52 modal_content.innerHTML = data.html; 53 }, 54 }); 55 }); 56</script> 57