I have the following function which opens a modal and puts some value into a div. It works but the function looks ugly, I hope for improvements (maybe more dynamic).
submitDelete: function() {
// projects
$('button[name="removeProj"]').on('click', function(e){
var $form = $(this).closest('form'); // closest parent form
var $id = $(this).data('id');
var $title = $(this).data('title');
var $createdAt = $(this).data('created-at');
var $updatedAt = $(this).data('updated-at');
e.preventDefault();
if($id != '') {
$("#prodId").empty().append($id);
} else {
$("#prodId").empty().append('-');
}
if($title != '') {
$("#prodTitle").empty().append($title);
} else {
$("#prodTitle").empty().append('-');
}
if($createdAt != '') {
$("#prodCreatedAt").empty().append($createdAt);
} else {
$("#prodCreatedAt").empty().append('-');
}
if($updatedAt != '') {
$("#prodUpdatedAt").empty().append($updatedAt);
} else {
$("#prodUpdatedAt").empty().append('-');
}
$('#confirm').modal({ backdrop: 'static', keyboard: false })
$('#delete').click(function() {
$form.trigger('submit'); // submit the form
});
});