Null url fix (#7408)

* RelatedModelField fix

Handle edge case where URL evaluates as null

* Handle undefined field
This commit is contained in:
Oliver 2024-06-05 10:40:05 +10:00 committed by GitHub
parent 7b179aaf95
commit 3ecbd64bf7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -59,12 +59,17 @@ export function RelatedModelField({
if (field.value === pk) return;
if (
field.value !== null &&
field.value !== undefined &&
field.value !== ''
field?.value !== null &&
field?.value !== undefined &&
field?.value !== ''
) {
const url = `${definition.api_url}${field.value}/`;
if (!url) {
setPk(null);
return;
}
api.get(url).then((response) => {
let pk_field = definition.pk_field ?? 'pk';
if (response.data && response.data[pk_field]) {