Skip to content

Commit 30a4847

Browse files
author
Henry Hadlow
committed
Add javascript counter to government response
1 parent 234d90d commit 30a4847

6 files changed

Lines changed: 8 additions & 5 deletions

File tree

File renamed without changes.

app/models/government_response.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ class GovernmentResponse < ActiveRecord::Base
22
belongs_to :petition, touch: true
33

44
validates :petition, presence: true
5-
validates :summary, presence: true, length: { maximum: 500 }
5+
validates :summary, presence: true, length: { maximum: 200 }
66
validates :details, length: { maximum: 4000 }, allow_blank: true
77

88
after_create do

app/views/admin/government_response/_petition_action_government_response.html.erb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
<%= form_row :for => [f.object, :summary] do %>
44
<%= f.label :summary, 'Summary quote', class: 'form-label' %>
55
<%= error_messages_for_field f.object, :summary %>
6-
<%= f.text_area :summary, rows: 3, cols: 70, tabindex: increment, class: 'form-control' %>
6+
<%= f.text_area :summary, rows: 3, cols: 70, tabindex: increment, 'data-max-length': 200, class: 'form-control' %>
7+
<p class="character-count">200 characters max</p>
78
<% end %>
89

910
<%= form_row :for => [f.object, :details] do %>
@@ -14,3 +15,5 @@
1415

1516
<%= email_signatures_with_count_submit_button(f, petition) %>
1617
<% end -%>
18+
19+
<%= javascript_include_tag 'character-counter' %>

app/views/layouts/application.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
<%= render 'application/footer' %>
3838
<%= javascript_include_tag 'application' %>
3939
<% if create_petition_page? %>
40-
<%= javascript_include_tag 'create-petition' %>
40+
<%= javascript_include_tag 'character-counter' %>
4141
<% end %>
4242
<% end %>
4343
</body>

config/initializers/assets.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
delayed/web/application.css
1616
ie.js
1717
admin.js
18-
create-petition.js
18+
character-counter.js
1919
)
2020

2121
# Compress JavaScript assets.

spec/models/government_response_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
it { is_expected.to validate_presence_of(:petition) }
2020
it { is_expected.to validate_presence_of(:summary) }
21-
it { is_expected.to validate_length_of(:summary).is_at_most(500) }
21+
it { is_expected.to validate_length_of(:summary).is_at_most(200) }
2222
it { is_expected.to validate_length_of(:details).is_at_most(4000) }
2323
end
2424

0 commit comments

Comments
 (0)