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
Ensure all hidden form fields in test overview filter #5464
Conversation
Issue: https://progress.opensuse.org/issues/154537 The code was skipping elements that already existed in the form, and this resulted in elements with multiple values to only keep one value. Now the elements to be added are collected and only added to the form after the loop. Bug was introduced in 2f6b7e0
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #5464 +/- ##
=======================================
Coverage 98.38% 98.38%
=======================================
Files 389 389
Lines 37829 37832 +3
=======================================
+ Hits 37217 37220 +3
Misses 612 612 ☔ View full report in Codecov by Sentry. |
for (var i = 0; i < hiddenInputs.length; i++) { | ||
$('#filter-form').append(hiddenInputs[i]); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would avoid the repeated calls to $('#filter-form')
in the loop and stick to standard JavaScript (as we probably shouldn't introduce more jQuery code at this point):
for (var i = 0; i < hiddenInputs.length; i++) { | |
$('#filter-form').append(hiddenInputs[i]); | |
} | |
const filterForm = document.getElementById('filter-form'); | |
hiddenInputs.forEach(i => filterForm.appendChild(i)); |
Probably the code that creates the input elements should also just use document.createElement('input')
and normal DOM APIs.
It is not obvious at all why your change makes a difference but it is because of what the code passed via paramHandler
does. That means you could probably also just change that code and make it skip those elements, e.g. replace if (formElement) {
with if (formElement && !formElement.hidden) {
. This would avoid an extra array and loop.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried now:
if (formElement && !formElement.hidden)
but then it is always skipping the last distri mentioned in the query parameters...
I need to debug this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So apparently in the first call of the paramHandler
form[key]
is undefined. In the second it''s returning HTMLInputElement
(hidden). After that it returns a RadioNodeList
. Possibly because there are now two elements already. Not sure yet how I should handle that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also I would like to add that I didn't introduce any new jquery code. I just moved it from one loop to the other.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, then your approach might be simpler after all. And it is true that the code was just moved.
Issue: https://progress.opensuse.org/issues/154537
The code was skipping elements that already existed in the form, and this resulted in elements with multiple values to only keep one value. Now the elements to be added are collected and only added to the form after the loop.
Bug was introduced in 2f6b7e0