From 682b2b4b2fa6bf3bd4f75ae9445e01b1c44b1304 Mon Sep 17 00:00:00 2001 From: Oliver Date: Wed, 30 Jun 2021 17:04:21 +1000 Subject: [PATCH] Support rendering / updating of date inputs --- .../order/purchase_order_detail.html | 3 +- InvenTree/templates/js/forms.js | 44 +++++++++++++++++-- 2 files changed, 42 insertions(+), 5 deletions(-) diff --git a/InvenTree/order/templates/order/purchase_order_detail.html b/InvenTree/order/templates/order/purchase_order_detail.html index 0ad73923a2..e5542f5816 100644 --- a/InvenTree/order/templates/order/purchase_order_detail.html +++ b/InvenTree/order/templates/order/purchase_order_detail.html @@ -21,7 +21,8 @@
{% if order.status == PurchaseOrderStatus.PENDING and roles.purchase_order.change %} + {% trans "Add Line Item" %} + {% endif %}
diff --git a/InvenTree/templates/js/forms.js b/InvenTree/templates/js/forms.js index a4baa8707f..de25b80146 100644 --- a/InvenTree/templates/js/forms.js +++ b/InvenTree/templates/js/forms.js @@ -501,6 +501,7 @@ function submitFormData(fields, options) { has_files = true; } } else { + // Normal field (not a file or image) form_data.append(name, value); @@ -601,12 +602,27 @@ function getFormFieldValue(name, field, options) { // Find the HTML element var el = $(options.modal).find(`#id_${name}`); + var value = null; + switch (field.type) { case 'boolean': - return el.is(":checked"); + value = el.is(":checked"); + break; + case 'date': + case 'datetime': + value = el.val(); + + // Ensure empty values are sent as nulls + if (!value || value.length == 0) { + value = null; + } + break; default: - return el.val(); + value = el.val(); + break; } + + return value; } @@ -705,7 +721,7 @@ function handleFormErrors(errors, fields, options) { // Add the 'has-error' class $(options.modal).find(`#div_id_${field_name}`).addClass('has-error'); - var field_dom = $(options.modal).find(`#id_${field_name}`); + var field_dom = $(options.modal).find(`#errors-${field_name}`); // $(options.modal).find(`#id_${field_name}`); var field_errors = errors[field_name]; @@ -719,7 +735,7 @@ function handleFormErrors(errors, fields, options) { ${error_text} `; - $(html).insertAfter(field_dom); + field_dom.append(html); } } else { @@ -1091,6 +1107,9 @@ function constructField(name, parameters, options) { html += ``; // input-group } + // Div for error messages + html += `
`; + if (parameters.help_text) { html += constructHelpText(name, parameters, options); } @@ -1173,6 +1192,9 @@ function constructInput(name, parameters, options) { case 'file upload': func = constructFileUploadInput; break; + case 'date': + func = constructDateInput; + break; default: // Unsupported field type! break; @@ -1380,6 +1402,20 @@ function constructFileUploadInput(name, parameters, options) { } +/* + * Construct a field for a date input + */ +function constructDateInput(name, parameters, options) { + + return constructInputOptions( + name, + 'dateinput form-control', + 'date', + parameters + ); +} + + /* * Construct a 'help text' div based on the field parameters *