Permalink
Browse files

Render grid hidden inputs in a table cell. Closes #339.

One of the effects of the changes made for the upgrade to Formtastic 2.1
(#227) apparently had the effect of wrapping the hidden inputs for question
ID and response ID in `li` tags. Those inputs were being rendered directly
into a `tr` (i.e., outside of any cell). This was illegal nesting, so the
browser relocated the `li`s (and the inputs) to somewhere they could legally
be rendered.

This seems to have moved them enough that they were no longer matched by the
jQuery selector used for submitting partial results. They were still in the
`form` overall and so were submitted when the whole page was submitted.

Moving the inputs to somewhere an `li` can legally be nested fixes this
problem.
  • Loading branch information...
1 parent 5b5b71b commit 03cbc8a81dd2933bf6be496be1b0535f1a3bfb1f @rsutphin rsutphin committed Jun 21, 2012
Showing with 8 additions and 7 deletions.
  1. +8 −7 app/views/partials/_question_group.html.haml
@@ -18,13 +18,14 @@
%th  
- ten_questions.each_with_index do |q, i|
%tr{:id => "q_#{q.id}", :class => "q_#{renderer} #{q.css_class(@response_set)}"}
- - if q.pick == "one"
- - r = response_for(@response_set, q, nil, g)
- - i = response_idx # increment the response index since the answer partial skips for q.pick == one
- = f.semantic_fields_for i, r do |ff|
- = ff.input :question_id, :as => :quiet
- = ff.input :id, :as => :quiet unless r.new_record?
- %th= q.split_text(:pre)
+ %th
+ = q.split_text(:pre)
+ - if q.pick == "one"
+ - r = response_for(@response_set, q, nil, g)
+ - i = response_idx # increment the response index since the answer partial skips for q.pick == one
+ = f.semantic_fields_for i, r do |ff|
+ = ff.input :question_id, :as => :quiet
+ = ff.input :id, :as => :quiet unless r.new_record?
- q.answers.each do |a|
%td= render a.custom_renderer || '/partials/answer', :g => g, :q => q, :a => a, :f => f
%th= q.split_text(:post)

4 comments on commit 03cbc8a

Contributor

jefflunt replied Sep 11, 2012

I believe this commit might misalign grids, shifting the answer labels on the top of the grid one table cell to the left, so that the first answer label is over the questions instead of the first answer.

This is because the %th that's added in each row of the questions/radio buttons needs to be matched with a %th in the top row, so that every row of the table has the same number of cells. If the answers and answer text are misaligned, it can become unclear which answers/radio buttons actually go with which answer text, which results in invalid data.

Contributor

rsutphin replied Sep 11, 2012

@normalocity can you provide a sample survey that demonstrates the problem you're describing? This commit should not change the number or position of cells in the header row — it just moves some illegally nested (non-cell) elements to a legal position.

@cmtoups I don't think your issue is related to this commit. (This commit is altering a view only; the issue you're describing would be in the model or the parser.) Unfortunately, I'm not familiar with how the :correct option is intended to work. Would you please as your question on the mailing list? Someone should be able to help you there —it may indeed be that you've found a bug, but the mailing list is the best place to ask.

Contributor

jefflunt replied Sep 11, 2012

I'm sorry, I'm going to have to withdraw my comment. I was testing against a different version of surveyor with a customized view, and didn't realize it. After testing it against the current version of master it seems to work as expected.

Please sign in to comment.