mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Support rendering / updating of date inputs
This commit is contained in:
parent
a92fc7cf2c
commit
682b2b4b2f
@ -21,7 +21,8 @@
|
|||||||
<div id='order-toolbar-buttons' class='btn-group' style='float: right;'>
|
<div id='order-toolbar-buttons' class='btn-group' style='float: right;'>
|
||||||
{% if order.status == PurchaseOrderStatus.PENDING and roles.purchase_order.change %}
|
{% if order.status == PurchaseOrderStatus.PENDING and roles.purchase_order.change %}
|
||||||
<button type='button' class='btn btn-primary' id='new-po-line'>
|
<button type='button' class='btn btn-primary' id='new-po-line'>
|
||||||
<span class='fas fa-plus-circle'></span> {% trans "Add Line Item" %}</button>
|
<span class='fas fa-plus-circle'></span> {% trans "Add Line Item" %}
|
||||||
|
</button>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
@ -501,6 +501,7 @@ function submitFormData(fields, options) {
|
|||||||
has_files = true;
|
has_files = true;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
// Normal field (not a file or image)
|
// Normal field (not a file or image)
|
||||||
form_data.append(name, value);
|
form_data.append(name, value);
|
||||||
|
|
||||||
@ -601,12 +602,27 @@ function getFormFieldValue(name, field, options) {
|
|||||||
// Find the HTML element
|
// Find the HTML element
|
||||||
var el = $(options.modal).find(`#id_${name}`);
|
var el = $(options.modal).find(`#id_${name}`);
|
||||||
|
|
||||||
|
var value = null;
|
||||||
|
|
||||||
switch (field.type) {
|
switch (field.type) {
|
||||||
case 'boolean':
|
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:
|
default:
|
||||||
return el.val();
|
value = el.val();
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -705,7 +721,7 @@ function handleFormErrors(errors, fields, options) {
|
|||||||
// Add the 'has-error' class
|
// Add the 'has-error' class
|
||||||
$(options.modal).find(`#div_id_${field_name}`).addClass('has-error');
|
$(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];
|
var field_errors = errors[field_name];
|
||||||
|
|
||||||
@ -719,7 +735,7 @@ function handleFormErrors(errors, fields, options) {
|
|||||||
<strong>${error_text}</strong>
|
<strong>${error_text}</strong>
|
||||||
</span>`;
|
</span>`;
|
||||||
|
|
||||||
$(html).insertAfter(field_dom);
|
field_dom.append(html);
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
@ -1091,6 +1107,9 @@ function constructField(name, parameters, options) {
|
|||||||
html += `</div>`; // input-group
|
html += `</div>`; // input-group
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Div for error messages
|
||||||
|
html += `<div id='errors-${name}'></div>`;
|
||||||
|
|
||||||
if (parameters.help_text) {
|
if (parameters.help_text) {
|
||||||
html += constructHelpText(name, parameters, options);
|
html += constructHelpText(name, parameters, options);
|
||||||
}
|
}
|
||||||
@ -1173,6 +1192,9 @@ function constructInput(name, parameters, options) {
|
|||||||
case 'file upload':
|
case 'file upload':
|
||||||
func = constructFileUploadInput;
|
func = constructFileUploadInput;
|
||||||
break;
|
break;
|
||||||
|
case 'date':
|
||||||
|
func = constructDateInput;
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
// Unsupported field type!
|
// Unsupported field type!
|
||||||
break;
|
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
|
* Construct a 'help text' div based on the field parameters
|
||||||
*
|
*
|
||||||
|
Loading…
Reference in New Issue
Block a user