diff --git a/app/views/branded/questions/_new_edit_question_datefield.html.erb b/app/views/branded/questions/_new_edit_question_datefield.html.erb index 631f38e..dce3c11 100644 --- a/app/views/branded/questions/_new_edit_question_datefield.html.erb +++ b/app/views/branded/questions/_new_edit_question_datefield.html.erb @@ -1,4 +1,4 @@ -<%# locals: { f, question, answer } %> +<%# locals: { f, question, answer, dataset } %>
<%= f.label(:text, raw(question.text), class: 'control-label') %> <%= date_field_tag('answer[text]', strip_tags(answer.text || question.default_value), class: 'form-control') %> diff --git a/app/views/branded/questions/_new_edit_question_numberfield.html.erb b/app/views/branded/questions/_new_edit_question_numberfield.html.erb index b20c628..dcafbf0 100644 --- a/app/views/branded/questions/_new_edit_question_numberfield.html.erb +++ b/app/views/branded/questions/_new_edit_question_numberfield.html.erb @@ -1,4 +1,4 @@ -<%# locals: { f, question, answer } %> +<%# locals: { f, question, answer, dataset } %>
<%= f.label(:text, raw(question.text), class: 'control-label') %> <%= number_field_tag('answer[text]', strip_tags(answer.text || question.default_value), class: 'form-control', step: :any) %> diff --git a/app/views/branded/questions/_new_edit_question_option_based.html.erb b/app/views/branded/questions/_new_edit_question_option_based.html.erb index 6334641..fe10e2e 100644 --- a/app/views/branded/questions/_new_edit_question_option_based.html.erb +++ b/app/views/branded/questions/_new_edit_question_option_based.html.erb @@ -1,4 +1,4 @@ -<%# locals: { f, question, answer } %> +<%# locals: { f, question, answer, dataset } %> <% options = question.question_options.by_number %> <% if question.question_format.checkbox? || question.question_format.multiselectbox? %> <%= f.label(:question_option_ids, sanitize(question.text), class: 'control-label') %> @@ -41,6 +41,6 @@ <% if question.option_comment_display %> <% text = question.question_format.rda_metadata? ? answer.answer_hash['text'] : answer.text %> <%= label_tag('answer[text]', _('Additional Information'), class: 'control-label') %> - <%= text_area_tag('answer[text]', text, id: "answer-text-#{question.id}", class: "form-control tinymce_answer") %> + <%= text_area_tag('answer[text]', text, id: "answer-text-#{question.id}-dataset-#{dataset.id}", class: "form-control tinymce_answer") %> <% end %>
diff --git a/app/views/branded/questions/_new_edit_question_textarea.html.erb b/app/views/branded/questions/_new_edit_question_textarea.html.erb new file mode 100644 index 0000000..85874f6 --- /dev/null +++ b/app/views/branded/questions/_new_edit_question_textarea.html.erb @@ -0,0 +1,17 @@ +<%# locals: { f, question, answer, dataset, locking } %> +<%# + When locking variable is true, this partial renders a plain paragraph with the question answer or default value instead. + Since the partial answers/_locking reuses the partial answers/_new_edit which reuses this partial within, when a stale answer is found + the browser renders two forms (first the stale answer form followed by the latest answer saved). This reusability comes with a side-effect, + i.e. the browser might end up with duplicate ids for the form controls and therefore re-loading tinymce for the locking form becomes + rather cumbersome. As such, this workaround, simplifies the logic when a stale answer is found by rendering the html of the answer directly + within a paragraph. +%> +
+ <%= f.label(:text, sanitize(question.text), class: 'control-label') %> + <% if locking || readonly %> + <%= sanitize("

#{answer.text || question.default_value}

") %> + <% else %> + <%= text_area_tag('answer[text]', answer.text || question.default_value, id: "answer-text-#{question.id}-dataset-#{dataset.id}", class: "form-control tinymce_answer") %> + <% end %> +
\ No newline at end of file diff --git a/app/views/branded/questions/_new_edit_question_textfield.html.erb b/app/views/branded/questions/_new_edit_question_textfield.html.erb new file mode 100644 index 0000000..cf05b45 --- /dev/null +++ b/app/views/branded/questions/_new_edit_question_textfield.html.erb @@ -0,0 +1,5 @@ +<%# locals: { f, question, answer, dataset } %> +
+ <%= f.label(:text, sanitize(question.text), class: 'control-label') %> + <%= text_field_tag('answer[text]', strip_tags(answer.text || question.default_value), class: 'form-control') %> +
\ No newline at end of file