From 8a18a29a3e3fd185cafc9f760b05a9a45e9e045d Mon Sep 17 00:00:00 2001 From: Ombental <30341654+Ombental@users.noreply.github.com> Date: Sat, 26 Aug 2023 12:41:31 +0300 Subject: [PATCH 1/2] try patching django select2 dependent fields for inlines --- .../static/django_select2/django_select2.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/django_select2/static/django_select2/django_select2.js b/django_select2/static/django_select2/django_select2.js index 01db20b5..16040611 100644 --- a/django_select2/static/django_select2/django_select2.js +++ b/django_select2/static/django_select2/django_select2.js @@ -24,11 +24,20 @@ field_id: $element.data('field_id') } + var dependentFields = $element.data('select2-dependent-fields') var dependentFields = $element.data('select2-dependent-fields') if (dependentFields) { dependentFields = dependentFields.trim().split(/\s+/) $.each(dependentFields, function (i, dependentField) { - result[dependentField] = $('[name=' + dependentField + ']', $element.closest('form')).val() + var formValue = $('[name=' + dependentField + ']', $element.closest('form')).val(); + // This is for inlines, I checked this for a specific case + if (formValue === null || formValue === undefined) { + var newFieldName = $element[0].name.split('-', 2).join('-') + '-' + dependentField; + var formsetValue = $('[name=' + newFieldName + ']', $element.closest('.form-row')).val(); + result[dependentField] = formsetValue; + } else { + result[dependentField] = formValue; + } }) } From a1d9785f05e171103fe786ee4eaa4a77e9b068e6 Mon Sep 17 00:00:00 2001 From: Ombental <30341654+Ombental@users.noreply.github.com> Date: Sat, 26 Aug 2023 12:43:12 +0300 Subject: [PATCH 2/2] fix: remove duplicate lines --- django_select2/static/django_select2/django_select2.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/django_select2/static/django_select2/django_select2.js b/django_select2/static/django_select2/django_select2.js index 16040611..0df24790 100644 --- a/django_select2/static/django_select2/django_select2.js +++ b/django_select2/static/django_select2/django_select2.js @@ -23,8 +23,6 @@ page: params.page, field_id: $element.data('field_id') } - - var dependentFields = $element.data('select2-dependent-fields') var dependentFields = $element.data('select2-dependent-fields') if (dependentFields) { dependentFields = dependentFields.trim().split(/\s+/)