Skip to content

Fix dynamic formset prefix on staff questionnaire form#2745

Merged
niklasmohrin merged 2 commits into
e-valuation:mainfrom
niklasmohrin:question-assignment-formset
Jun 29, 2026
Merged

Fix dynamic formset prefix on staff questionnaire form#2745
niklasmohrin merged 2 commits into
e-valuation:mainfrom
niklasmohrin:question-assignment-formset

Conversation

@niklasmohrin

Copy link
Copy Markdown
Member

Closes #2742

Ough, this was annoying to debug (see the issue). So the problem is that the underlying ids changed so our call to makeFormSortable passed the wrong prefix which meant that the dynamic formset code did not identify the numbering in the form field ids correctly and kept generating rows with the same ids. For some reason, our backend just ignored the fact that it received an array of values where it expected only a single one and decided to just sweep all but one value under the table.

I also changed the makeFormSortable callback to remove the form-template class from newly created rows because the template we use stays in place and the rows are not the template, although I think that the dynamic formset code queries the template node only once in the beginning, otherwise we would be seeing rows with duplicate values created in all kinds of places.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Again, is there something we can meaningfully test here? For this one I am learning more towards "this just has to work", but we manged to not catch this once in review, so I don't know

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

On the bright side, at least the AI also didn't catch this, so we can all sleep tight :^)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

If we want a test to ensure this doesn't stop working, I think live/frontend test, re-order, assert "order" field in database is what we should do. Should be doable in ~10ish lines, assuming it's somewhat possible to simulate a drag+drop for reordering in Selenium.

@janno42 janno42 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@richardebeling richardebeling left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

lgtm, thanks

@niklasmohrin

Copy link
Copy Markdown
Member Author

So I wrote a frontend test which moves them using the nice ActionChains(...).drag_and_drop API. This worked, but then I figured we might want to check something more involved than just two elements and one move. Like, five elements and two moves. An hour later, I finally notice why it doesn't work, after the first move the dragged element is still a "ghost" and waiting for a "dragend" event. Oh noes.

So turns out that this whole dragging thing is still absolutely broken, and not just in selenium but in the official webdriver interface. See https://redirect.github.com/w3c/webdriver/issues/1488 and https://redirect.github.com/SeleniumHQ/selenium/issues/12525

I will just revert to the easy test case :(

Comment on lines +270 to +272
add_another.click()
add_another.click()
add_another.click()

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Is there any reason why you click three times on the button? I would think once should be enough or do you try to trigger something else?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Just simulating my personal interaction with the site :D

The real reason is that I wanted to check what happens if there are empty rows at the end and inbetween (notice that I use rows 5 and 7 instead of 5 and 6 below)

@niklasmohrin niklasmohrin merged commit e2c3b26 into e-valuation:main Jun 29, 2026
16 checks passed
@niklasmohrin niklasmohrin deleted the question-assignment-formset branch June 29, 2026 15:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

Questions are not created correctly

4 participants