Last active
August 5, 2021 09:30
-
-
Save gabelorm/bd6a46e4940355e284a38226c41fdf4c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
A form populates a table from form entry with a unique ID. After the submit button is clicked, it creates a file where you can save and print. It works perfectly but when an entry is edited, any subsequent entry doesn't create a new file but rather update the last entry. In other words, the unique ID doesn't increase anymore unless the system is relaunched. | |
Below is the function for my create button | |
$('#create_btn').click(function () { | |
$('#create_invoice').get(0).reset(); | |
$('#action').val('create_invoice'); | |
$('#title').text('DONATION'); | |
$('#action_create_invoice').val('Donate'); | |
$('#invoice_items').empty(); | |
calculateTotal(); | |
$("#invoice_status").empty(); | |
$("#invoice_status").html(`<option value="paid">Paid</option><option value="unpaid">Unpaid</option>`); | |
$('#date').val(moment().format('YYYY-MM-DD')); | |
$('#due_date').val(moment().format('YYYY-MM-DD')); | |
cloned.clone().appendTo('#invoice_table'); | |
showCompanyDetails(); | |
}); | |
And below is the function for the update button | |
$.fn.editInvoice = function (i) { | |
$('#create_invoice').get(0).reset(); | |
$('#action_create_invoice').val('Update Donation'); | |
$('#action').val('create_invoice'); | |
$('#title').text('DONATION: ' + invoices[i]._id); | |
$('#invoice_items').empty(); | |
$("#invoice_status").empty(); | |
$("#invoice_status").html(`<option value="unpaid">Unpaid</option><option value="paid">Paid</option>`); | |
$("#invoice_status option").filter(function () { | |
return $(this).val() == invoices[i].invoice_status; | |
}).prop("selected", true); | |
showDetails(1, i); | |
if (Array.isArray(invoices[i].invoice_product)) { | |
invoices[i].invoice_product.forEach(function (invoice, index) { | |
let item = invoiceRows(1, i, index); | |
$('#invoice_items').append(item); | |
}); | |
} | |
else { | |
let item = invoiceRows(1, i, -1); | |
$('#invoice_items').append(item); | |
} | |
if (invoices[i].invoice_shipping) { | |
$('#invoice_shipping').val(invoices[i].invoice_shipping); | |
} | |
calculateTotal(); | |
let margin = 1 * -100 + '%'; | |
$('.wrapper').animate({ | |
marginLeft: margin | |
}, 200); | |
} | |
I want to achieve this | |
When I edit an entry, I should be able to create a new entry with a new unique ID. | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment