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