Adding ranking and sorting (drag and drop) question types #284
Replies: 1 comment
|
Thanks @Sunilshah-7, this is great, and I agree with the API in general. As for steps to implement it, I'd suggest forking the repo and making a new branch to work on, then submitting a PR when done and we can review it. As for the implementation plan, I would suggest starting with a minimal working example of each question type, maybe starting with |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Description
Hi, GW OSPO is building a survey using surveydown where respondents drag software cards into different bins. Since there's no native question type for this, I ended up using sortable::bucket_list() with sd_question_custom() plus a bunch of manual code to serialize the bin state and push it into session$userData$all_data so it actually gets saved to the database. It works, but it's around 100 lines of app code for one question and it touches package internals.
After talking with the team about this and we sketched out what a native version could look like. This picks up where PR #163 left off, without using sortable. I'd like to work on PR for it, but wanted to open this issue first to agree on the API.
Proposed API
A ranking type, where you drag items into an order:
And a sorting type, where you drag items into bins:
bins would only apply to the sorting type, similar to how row only applies to matrix questions.
For storage, ranking can be saved in the final order as a pipe-joined string in one column (like mc_multiple does), and sorting saves one column per bin (albums_sorted_love_it, etc.), following the matrix {id}_{row} naming. But open to other formats.
Implementation wise, the registry in R/question_types.R seems like it makes this pretty clean: two new render/restore entries, the new args threaded through sd_question(), and a JS file for the drag and drop behavior registered in the lua filter.
Happy to have any discussion for this feature. If this sounds good, I'll start on it.
All reactions