diff --git a/InvenTree/templates/js/forms.js b/InvenTree/templates/js/forms.js index fb3963d9e2..dd72031149 100644 --- a/InvenTree/templates/js/forms.js +++ b/InvenTree/templates/js/forms.js @@ -729,6 +729,10 @@ function initializeRelatedField(name, field, options) { data = item.element.instance; } + if (!data.pk) { + return $(searching()); + } + // Custom formatting for the search results if (field.model) { // If the 'model' is specified, hand it off to the custom model render @@ -750,6 +754,10 @@ function initializeRelatedField(name, field, options) { data = item.element.instance; } + if (!data.pk) { + return $(searching()); + } + // Custom formatting for selected item if (field.model) { // If the 'model' is specified, hand it off to the custom model render @@ -794,6 +802,11 @@ function initializeRelatedField(name, field, options) { } +// Render a 'no results' element +function searching() { + return `{% trans "Searching" %}...`; +} + /* * Render a "foreign key" model reference in a select2 instance. * Allows custom rendering with access to the entire serialized object.