Fix rendering during search

This commit is contained in:
Oliver 2021-06-29 12:48:56 +10:00
parent 9312a5d3b4
commit f18c2a7a3d

View File

@ -729,6 +729,10 @@ function initializeRelatedField(name, field, options) {
data = item.element.instance; data = item.element.instance;
} }
if (!data.pk) {
return $(searching());
}
// Custom formatting for the search results // Custom formatting for the search results
if (field.model) { if (field.model) {
// If the 'model' is specified, hand it off to the custom model render // 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; data = item.element.instance;
} }
if (!data.pk) {
return $(searching());
}
// Custom formatting for selected item // Custom formatting for selected item
if (field.model) { if (field.model) {
// If the 'model' is specified, hand it off to the custom model render // 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 `<span>{% trans "Searching" %}...</span>`;
}
/* /*
* Render a "foreign key" model reference in a select2 instance. * Render a "foreign key" model reference in a select2 instance.
* Allows custom rendering with access to the entire serialized object. * Allows custom rendering with access to the entire serialized object.