Update placeholders for serial numbers when creating a new stock item

This commit is contained in:
Oliver 2021-11-27 00:17:31 +11:00
parent ef7a9b5152
commit ad6e34953b
2 changed files with 23 additions and 1 deletions

View File

@ -28,6 +28,7 @@
disableFormInput,
enableFormInput,
hideFormInput,
setFormInputPlaceholder,
setFormGroupVisibility,
showFormInput,
*/
@ -1276,6 +1277,11 @@ function initializeGroups(fields, options) {
}
}
// Set the placeholder value for a field
function setFormInputPlaceholder(name, placeholder, options) {
$(options.modal).find(`#id_${name}`).attr('placeholder', placeholder);
}
// Clear a form input
function clearFormInput(name, options) {
updateFieldValue(name, null, {}, options);

View File

@ -158,10 +158,26 @@ function stockItemFields(options={}) {
// If a "trackable" part is selected, enable serial number field
if (data.trackable) {
enableFormInput('serial_numbers', opts);
// showFormInput('serial_numbers', opts);
// Request part serial number information from the server
inventreeGet(`/api/part/${data.pk}/serial-numbers/`, {}, {
success: function(data) {
var placeholder = '';
if (data.next) {
placeholder = `{% trans "Next available serial number" %}: ${data.next}`;
} else if (data.latest) {
placeholder = `{% trans "Latest serial number" %}: ${data.latest}`;
}
setFormInputPlaceholder('serial_numbers', placeholder, opts);
}
});
} else {
clearFormInput('serial_numbers', opts);
disableFormInput('serial_numbers', opts);
setFormInputPlaceholder('serial_numbers', '{% trans "This part cannot be serialized" %}', opts);
}
// Enable / disable fields based on purchaseable status