diff --git a/django_select2/static/django_select2/django_select2.js b/django_select2/static/django_select2/django_select2.js index 01db20b5..0df24790 100644 --- a/django_select2/static/django_select2/django_select2.js +++ b/django_select2/static/django_select2/django_select2.js @@ -23,12 +23,19 @@ page: params.page, field_id: $element.data('field_id') } - 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; + } }) }