Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #136 -- Add dependent-field support to formsets #231

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

Ombental
Copy link

I labeled this as minor because I didn't take into consideration all use cases but my private one, though I do think it answers most of the needs. this is django admin oriented

@codingjoe codingjoe changed the title Minor Attempt to fix issue #136 Fix #136 -- Add dependent-field support to formsets Aug 29, 2023
Copy link
Owner

@codingjoe codingjoe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @Ombental,

Thank you for your contribution. I appreciate your help. It looks like a promising start. I left you a small suggestion. Besides that, I'd appreciate it if you could add a test. The selenium setup is a bit tricky. Don't hesitate to ask for help, regarding the tests.

Cheers!
Joe

Comment on lines +30 to +38
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;
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe you can simply this a little and drop the else branch, like so:

Suggested change
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;
}
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;

@elavaud
Copy link

elavaud commented Jan 24, 2024

This is great and solve our problems. Looking forward a release

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants