function getDataForEdit(name) { $.ajax({ type: 'get', url: `/api/v1/categories?name=${name}`, success: function (result) { // Get elements inside the editCategoryModal const modal_categoryName = document.getElementById('editCategoryModalName'); const modal_categoryDescription = document.getElementById('editCategoryModalDescription'); const modal_categoryid = document.getElementById('editCategoryModalId'); modal_categoryName.value = result.name; modal_categoryDescription.value = result.description; modal_categoryid.value = result.id; }, error: function (data) { console.log('!!!! ERROR !!!!', data); // Hide overlay with spinner $('.loader-overlay').removeClass('active'); // Close the modal $('.modal').modal('hide'); createNewToast(' Something went wrong. The category does no longer exist.', "text-bg-danger") } }); } function primeCreateNew() { const form = document.getElementById('CategoryModalForm'); form.setAttribute('method', 'POST'); document.getElementById('editCategoryModalLabel').innerText = 'Create a new category'; $('.form-control').val(''); return true; } function primeEdit() { const form = document.getElementById('CategoryModalForm'); document.getElementById('editCategoryModalLabel').innerText = 'Edit category'; form.setAttribute('method', 'PATCH'); return true; }