I am somehow new to jQuery and is going through some code of a project.
The existing jQuery looks like this and this pops up a modal of confirmation upon delete:
{% for profile in profiles %}
$("#delete_{{ profile.id }}").mousedown(function(event){
let action = "deleteprofile"
$.confirm({
title: 'Delete',
content: 'Are you sure?',
buttons: {
confirm: function () {
submit_to_modal({
'profile_id': "{{ profile.id }}"
},
action)
},
cancel: function () {
$.alert('cancel');
}
}
});
})
{% endfor %}
I think this project uses jquery-confirm after searching for similarities in the code, I read about it here: https://craftpip.github.io/jquery-confirm/ it can also be found here: How to display a confirm box before submitting a form using jquery confirm?
So upon the click of a button in the html. e.g
<button id="delete_{{ profile.id }}">Delete</button>
The jQuery will be triggered producing a confirmation. After confirmation the deleteprofile action which is from the views of the backend will be triggered and it will make the DELETE request.
However, I want to be able to make an edit modal from this.
Where an item from a list of items, such as profiles when clicked will produce a modal.
I searched for it and found these resources:
Bootstrap: Modal dialog for editing data dynamically
Jquery .on() submit event
But all of them don't receive the which will trigger the specific item. For example, I only want to edit, profile-001, but it can't be done with these samples. I already tried them and the modal didn't pop out.
I found this: How to make an "Edit User" form inside Bootstrap Modal using JQUERY?
But this is on PHP, I am using only jinja for this. I also couldn't replicate this on the html as I am fairly new to frontend stuff.
How do you usually add input fields to modals in jinja, or in jQuery in this case? I want to be able to pop out a modal which will have input values, which will be received by jQuery per item.
Any source to what I want to find is also welcome, I have been scanning four hours already and tried testing it but I can't get a modal to pop up except for the deletion modal.
question from:
https://stackoverflow.com/questions/65855042/html-and-jquery-modal-for-editing