Skip to content

Commit 751af1f

Browse files
add support for rich text textarea
2 parents 2dfab31 + e732803 commit 751af1f

14 files changed

Lines changed: 11605 additions & 12 deletions

File tree

app/assets/javascripts/quill.js

Lines changed: 11440 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/assets/stylesheets/quill-snow.css

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/helpers/application_helper.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,8 @@ def question_type_javascript_params(question)
149149
"form.querySelector(\"##{question.ui_selector}\") && form.querySelector(\"##{question.ui_selector}\").dataset.rawValue"
150150
elsif question.question_type == 'textarea'
151151
"form.querySelector(\"##{question.ui_selector}\") && form.querySelector(\"##{question.ui_selector}\").value"
152+
elsif question.question_type == 'rich_textarea'
153+
"form.querySelector(\"##{question.ui_selector}\") && form.querySelector(\"##{question.ui_selector}\").value"
152154
elsif question.question_type == 'radio_buttons'
153155
"form.querySelector(\"input[name=#{question.ui_selector}]:checked\") && form.querySelector(\"input[name=#{question.ui_selector}]:checked\").value"
154156
elsif question.question_type == 'star_radio_buttons'

app/models/form.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,10 @@ def check_expired
264264
end
265265
end
266266

267+
def has_rich_text_questions?
268+
questions.where(question_type: "rich_textarea").exists?
269+
end
270+
267271
def self.archive_expired!
268272
Form.where("expiration_date is not null and expiration_date < NOW() and aasm_state <> 'archived'").find_each do |form|
269273
@event = Event.log_event(Event.names[:form_archived], 'Form', form.uuid, "Form #{form.name} archived at #{DateTime.now}", 1)

app/models/question.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ class Question < ApplicationRecord
2525
'dropdown',
2626
'combobox',
2727
# Custom elements
28+
'rich_textarea',
2829
'text_display',
2930
'custom_text_display',
3031
'states_dropdown',

app/views/admin/forms/example.html.erb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,10 @@
9292
<!--- End demo content -->
9393
<script src="<%= touchpoint_url(@form.short_uuid, format: :js) %>" async></script>
9494
<script>
95+
document.addEventListener('onTouchpointsFormLoaded', function() {
96+
console.log("fired onTouchpointsFormLoaded")
97+
});
98+
9599
document.addEventListener('onTouchpointsModalClose', function() {
96100
console.log("fired onTouchpointsModalClose")
97101
});

app/views/admin/questions/_question.html.erb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
<% @form_component_path = 'components/forms/edit/question_types/combobox' %>
3030
<% elsif question.question_type == "textarea" %>
3131
<% @form_component_path = 'components/forms/edit/question_types/text_area' %>
32+
<% elsif question.question_type == "rich_textarea" %>
33+
<% @form_component_path = 'components/forms/edit/question_types/rich_textarea' %>
3234
<% elsif question.question_type == "hidden_field" %>
3335
<% @form_component_path = 'components/forms/edit/question_types/hidden_field' %>
3436
<% elsif question.question_type == "custom_text_display" %>

app/views/components/forms/_custom.html.erb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@
7373
<%= render 'components/forms/question_types/combobox', form: form, question: question, question_number: multi_section_question_number %>
7474
<% elsif question.question_type == "textarea" %>
7575
<%= render 'components/forms/question_types/text_area', form: form, question: question, question_number: multi_section_question_number %>
76+
<% elsif question.question_type == "rich_textarea" %>
77+
<%= render 'components/forms/question_types/rich_textarea', form: form, question: question, question_number: multi_section_question_number %>
7678
<% elsif question.question_type == "text_display" %>
7779
<%= render 'components/forms/question_types/text_display', form: form, question: question, question_number: multi_section_question_number %>
7880
<% elsif question.question_type == "date_select" %>

app/views/components/forms/edit/_builder.html.erb

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<% @instruction_text_limit = 1500 %>
22
<% @disclaimer_text_limit = 1000 %>
3-
3+
<%= javascript_include_tag "quill.js" %>
4+
<%= stylesheet_link_tag "quill-snow.css" %>
45
<%= render 'admin/forms/logo_display', { form: form } %>
56
<hr
67
class="margin-top-3 margin-bottom-3"
@@ -376,4 +377,24 @@ function textCounter(field,maxlimit) {
376377
countfield.innerText = "" + (maxlimit - field.value.length) + " <%= t :characters_left %>";
377378
}
378379
}
380+
381+
document.addEventListener("DOMContentLoaded", function () {
382+
document.querySelectorAll(".quill").forEach((wrapper) => {
383+
const editorContainer = wrapper.querySelector(".editor");
384+
const hiddenInput = wrapper.querySelector("input[type=hidden]");
385+
386+
if (editorContainer && hiddenInput) {
387+
const quill = new Quill(editorContainer, {
388+
theme: 'snow',
389+
placeholder: 'Write something...',
390+
modules: {
391+
toolbar: [
392+
['bold', 'italic', 'underline'],
393+
[{ 'list': 'ordered'}, { 'list': 'bullet' }]
394+
]
395+
}
396+
});
397+
}
398+
});
399+
});
379400
</script>
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<%
2+
form_options = {
3+
class: "usa-textarea",
4+
required: question.is_required,
5+
maxlength: question.max_length,
6+
}
7+
8+
if question.help_text.present?
9+
form_options.merge!({
10+
"aria-describedby" => "question-id-#{question.id}-help-text"
11+
})
12+
end
13+
%>
14+
15+
<div class="usa-form-group quill">
16+
<%= render 'components/question_title_label', question: question %>
17+
<input
18+
type="hidden"
19+
name="my_model[rich_text]"
20+
id="<%= question.ui_selector %>">
21+
<div
22+
id="quill-editor-<%= question.ui_selector %>"
23+
class="editor"
24+
style="min-height: 100px;"></div>
25+
</div>

0 commit comments

Comments
 (0)