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

syncFieldWithNewRow incorrectly replacing row values className attribute when element not current within row #1579

Merged
merged 2 commits into from
Jul 7, 2024

Conversation

lucasnetau
Copy link
Collaborator

@lucasnetau lucasnetau commented Jul 4, 2024

Fixes #1575

When drag + drop a field from one row to a new row the function syncFieldWithNewRow() is called 3 times, once in the sortable update: callback which removes the existing row, and again in receive: callback. On the second call the oldRow value is an empty string, which resulted in the replace() call having an empty pattern and corrupting the classString.

Reimplemented syncFieldWithNewRow by operating on the classNames as an array, handling the case where we drop onto the same row or no row value exists.

Additionally syncFieldWithNewRow has been moved into the Helpers class to ensure it is directly testable with Jest and secondly to ensure it only does one task (no checkRowCleanup() on each call, delayed checkRowCleanup() to sortable stop())

@lucasnetau
Copy link
Collaborator Author

Original reporter confirms this resolves their issue

Copy link
Owner

@kevinchappell kevinchappell left a comment

Choose a reason for hiding this comment

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

looks good to me. nice fix.

Comment on lines +1479 to +1490
if (oldRow !== newRow) {
if (oldRow) {
currentClasses = currentClasses.filter(function(obj) {
return obj !== oldRow
})
}
if (newRow) {
currentClasses.push(newRow)
}
inputClassElement.val(currentClasses.join(' '))
}
}
Copy link
Owner

Choose a reason for hiding this comment

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

👍

@kevinchappell kevinchappell merged commit ccf699b into kevinchappell:master Jul 7, 2024
1 check passed
Copy link

github-actions bot commented Jul 7, 2024

🎉 This PR is included in version 3.19.12 🎉

The release is available on:

Your semantic-release bot 📦🚀

@lucasnetau lucasnetau deleted the fix/1575-sync branch July 7, 2024 22:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

How to make bootstrap classes not disappear when removing a field from a row and putting it in an empty place
2 participants