Conversation
they were being added to the end of the element, but there are some invisible elements there, so moving the question up seemed not to work for a while, but it was actually moving betwenn invisible elements. This is now fixed, since new questions are added right after the last one, thus avoiding the invisible elements.
70ff8d2 to
c0b9015
Compare
This made the binding to fire for every click on the wrapper element, thus creating a lot of child answer options.
839bf6c to
4d6b015
Compare
leio10
left a comment
There was a problem hiding this comment.
Great work, it seems much easier this way! 👏 👏 👍
| <%= cell("decidim/represent_user_group", form) %> | ||
| </div> | ||
| <% end %> | ||
| <% step_answers.each do |answer| %> |
There was a problem hiding this comment.
could you use each_with_index for the answer_idx variable?
There was a problem hiding this comment.
I don't think so, because I need to keep the counter between steps (which would be lost). Also, I need to skip the separators, so I'd need to keep track of those elements... I think it's easier to keep track using the answer_ids, but I'll give it another thought!
| class: "hollow secondary" | ||
| class: "hollow secondary", | ||
| data: { | ||
| toggle: [previous_step_dom_id, current_step_dom_id].join(" ") |
There was a problem hiding this comment.
Wow, I was looking for the JS part! 🤩 ❤️
There was a problem hiding this comment.
It turned out to be much easier than expected! 😄 Luckily, Foundation's toggler component allows for multiple toggles from the same element, this allowed me to implement the steps 😄
|
@microstudi whoops, sorry! I removed it myself, thanks for noticing! |
microstudi
left a comment
There was a problem hiding this comment.
This is an amazing work @mrcasals!
I have a couple of comments between the code, I might be wrong in both of them, please let me know.
About the general behaviour, I am only missing one thing, it is no possible to go from one step to the other using only URL changes (in this case it should be hashes).
I think it would be nice to show in the URL the current step:

=>

One problem of not doing so, is that when you are submitting the survey with errors it returns you to the step1, and it might well be that the error is not in that page, which is confusing. If URL navigation was in place, then we could return the first step with an error in it. That would give the user a much better feedback.
However, I am not sure if this is would be out of scope regarding what @decidim/product has asked.
Thanks again.
| # Public: Splits reponses by step, keeping the separator. Ruby doesn't | ||
| # seem to give a way to do this in the standard library, so we had to | ||
| # write our own version. | ||
| # | ||
| # Returns an array of steps. Each step is a list of the questions in that | ||
| # step, including the separator. | ||
| def responses_by_step | ||
| @responses_by_step ||= | ||
| begin | ||
| steps_acc = [[]] | ||
| step_index = 0 | ||
|
|
||
| responses.each do |response| | ||
| steps_acc[step_index] << response | ||
|
|
||
| if response.question.separator? | ||
| step_index += 1 | ||
| steps_acc[step_index] = [] | ||
| end | ||
| end | ||
| steps_acc | ||
| end | ||
| end |
There was a problem hiding this comment.
Not that I found anything wrong with this, but since you comment that there's no ruby method to do that, could this do the trick?
@responses_by_step ||= responses.chunk_while { |a,b| !a.question.separator? }There was a problem hiding this comment.
Oh, I didn't know about this one, thanks!
@microstudi for that we'd need a much more intelligent system: we'd need to locate the first field with an error, find its step and jump to that page... And sincerely I think that's out of the scope 😅 |
All right, but as I understand, this is a part of #5728 right?, because I see that it does not cover everything. Would it be more PRs to complete the EPIC? Maybe @carolromero could tell us what she thinks about this. |
|
@microstudi as explained in #5728, we treat that issue as an EPIC (I actually think Product has updated the title). This PR closes some of the criterias, while the rest will be covered in upcoming PRs. Anyway, the tests are now failing after the refactor you suggested, I'll look at this tomorrow. |
|
@mrcasals oops, sorry for the fuss then, thanks! |
|
@microstudi all green now! Can you re-review this please? 😄 /cc @decidim/core |
|
I've added a design tweak as explained in #5728 (comment) |
|
@decidim/core @microstudi I'm getting failures in Can we get this PR merged anyway to avoid conflicts? |
|
@mrcasals it seems to be a flaky test. Capybara sometimes seems to execute press a button, some times doesn't. I'm not really sure how to solve it, I'll keep investigating it. |
* develop: Include year in meetings card (decidim#6102) Add attachment enabled option to initiative types and initiatives (decidim#6036) Fix a flaky test in group profile conversations (decidim#6123) Add attachments to Initiatives (decidim#5844) Add initiatives export (decidim#6070) Improvements to conversations with more than one participant (decidim#6094) Elections module and election administration (decidim#6065) Separate forms in steps (decidim#6108) Add sorting by publishing date to initiatives (decidim#6016) Improve proposal preview: Use proposal card when previewing a proposal draft (decidim#6064) Newsletter templates fixes (decidim#6096) # Conflicts: # decidim-initiatives/app/models/decidim/initiative.rb # decidim-initiatives/spec/system/admin/initiative_types_controller_spec.rb
* feature/add_areas_to_initiatives: (30 commits) Adds areas to FO filters Fix lint issue Fixes rubocop issues Updates changelog Adds areas to initiatives Send notification when signature threshold reached (decidim#6098) Adds filter by initiative type to admin panel (decidim#6093) Require confirmation on exiting a survey mid-answering (decidim#6118) Information message when there isn't any Proposal (decidim#6063) Set email asset host dynamically (decidim#5888) Harmonizes the design of initiatives search in FO (decidim#6090) Include year in meetings card (decidim#6102) Add attachment enabled option to initiative types and initiatives (decidim#6036) Fix a flaky test in group profile conversations (decidim#6123) Add attachments to Initiatives (decidim#5844) Add initiatives export (decidim#6070) Improvements to conversations with more than one participant (decidim#6094) Elections module and election administration (decidim#6065) Separate forms in steps (decidim#6108) Add sorting by publishing date to initiatives (decidim#6016) ... # Conflicts: # decidim-initiatives/app/cells/decidim/initiatives/initiative_m_cell.rb # decidim-initiatives/app/commands/decidim/initiatives/admin/update_initiative.rb # decidim-initiatives/app/controllers/decidim/initiatives/initiatives_controller.rb # decidim-initiatives/app/forms/decidim/initiatives/admin/initiative_form.rb # decidim-initiatives/app/helpers/decidim/initiatives/application_helper.rb # decidim-initiatives/app/models/decidim/initiative.rb # decidim-initiatives/app/services/decidim/initiatives/initiative_search.rb # decidim-initiatives/app/views/decidim/initiatives/create_initiative/fill_data.html.erb # decidim-initiatives/app/views/decidim/initiatives/initiatives/_filters.html.erb # decidim-initiatives/app/views/decidim/initiatives/initiatives/_tags.html.erb # decidim-initiatives/config/locales/en.yml # decidim-initiatives/db/migrate/20200514085422_add_area_to_initiatives.rb # decidim-initiatives/db/migrate/20200514102631_add_area_enabled_option_to_initiatives.rb # decidim-initiatives/spec/forms/initiative_form_spec.rb # decidim-initiatives/spec/services/decidim/initiatives/initiative_search_spec.rb # decidim-initiatives/spec/shared/update_initiative_type_example.rb # decidim-initiatives/spec/system/admin/admin_manages_initiatives_spec.rb # decidim-initiatives/spec/system/admin/initiative_types_controller_spec.rb # decidim-initiatives/spec/system/filter_initiatives_spec.rb
* Survey steps * Add basic system tests * Add separators in admin area * Persist separators * Fix weird behavior when adding questions and moving them up they were being added to the end of the element, but there are some invisible elements there, so moving the question up seemed not to work for a while, but it was actually moving betwenn invisible elements. This is now fixed, since new questions are added right after the last one, thus avoiding the invisible elements. * Fix bug when adding a separator, buttons where not correct * Fix bug when adding questions on new survey * Hide separator from question types list * Fix bug on events binding This made the binding to fire for every click on the wrapper element, thus creating a lot of child answer options. * Prepare for step layout in public area * Paginate steps in public area * Handle survey submissions * Delete unused locale keys * Fix tests for public area on surveys * Generalize use case * Add missing tests * Add changelog * Fix wrong locale key * Hide spearators for anonymous users * Simplify code * Fix refactored method * Surveys font style fixes Co-authored-by: Javier Usobiaga <javier@swwweet.com> # Conflicts: # decidim-forms/app/commands/decidim/forms/answer_questionnaire.rb # decidim-forms/app/models/decidim/forms/question.rb # decidim-forms/app/views/decidim/forms/admin/questionnaires/_form.html.erb # decidim-forms/app/views/decidim/forms/questionnaires/_answer.html.erb # decidim-forms/app/views/decidim/forms/questionnaires/show.html.erb # decidim-forms/config/locales/en.yml # decidim-forms/lib/decidim/forms/test/factories.rb # decidim-forms/lib/decidim/forms/test/shared_examples/has_questionnaire.rb # decidim-forms/lib/decidim/forms/test/shared_examples/manage_questionnaires.rb # decidim_app-design/app/views/public/index.html.erb
* Survey steps * Add basic system tests * Add separators in admin area * Persist separators * Fix weird behavior when adding questions and moving them up they were being added to the end of the element, but there are some invisible elements there, so moving the question up seemed not to work for a while, but it was actually moving betwenn invisible elements. This is now fixed, since new questions are added right after the last one, thus avoiding the invisible elements. * Fix bug when adding a separator, buttons where not correct * Fix bug when adding questions on new survey * Hide separator from question types list * Fix bug on events binding This made the binding to fire for every click on the wrapper element, thus creating a lot of child answer options. * Prepare for step layout in public area * Paginate steps in public area * Handle survey submissions * Delete unused locale keys * Fix tests for public area on surveys * Generalize use case * Add missing tests * Add changelog * Fix wrong locale key * Hide spearators for anonymous users * Simplify code * Fix refactored method * Surveys font style fixes Co-authored-by: Javier Usobiaga <javier@swwweet.com> # Conflicts: # decidim_app-design/app/views/public/index.html.erb
🎩 What? Why?
Newer, simpler take on #5728. This PR replaces #6010.
📌 Related Issues
📋 Subtasks
CHANGELOGentry📷 Screenshots (optional)
Form with a separator to split into steps:

Public area: First step of the form

Public area: second step of the form
