Skip to content

Commit

Permalink
Add dependent-field support to formsets from PR codingjoe#231
Browse files Browse the repository at this point in the history
  • Loading branch information
mardukbp committed Jul 18, 2024
1 parent 07ea4b8 commit eb150b7
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion django_select2/static/django_select2/django_select2.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,13 @@
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;
formValue = $('[name=' + newFieldName + ']', $element.closest('.form-row')).val();
}
result[dependentField] = formValue;
})
}

Expand Down

0 comments on commit eb150b7

Please sign in to comment.