Skip to content

Commit

Permalink
fixup! a14ce58 Better validation highlighting
Browse files Browse the repository at this point in the history
  • Loading branch information
garethrees committed Mar 6, 2015
1 parent 9e1bd38 commit 83a47a9
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 5 deletions.
32 changes: 29 additions & 3 deletions app/views/admin_public_body_headings/_form.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,24 @@
<%= error_messages_for 'heading' %>
<% if @heading.errors.any? %>
<ul>
<% @heading.errors.each do |attr, message| %>
<% unless attr.to_s.starts_with?('translation') %>
<li><%= message %></li>
<% end %>
<% end %>
</ul>
<% end %>

<% @heading.ordered_translations.each do |translation| %>
<% if translation.errors.any? %>
<%= locale_name(translation.locale.to_s) || translation.locale.to_s %>
<ul>
<% translation.errors.each do |attr, message| %>
<li><%= message %></li>
<% end %>
</ul>
<% end %>
<% end %>


<!--[form:public_body_heading]-->

Expand All @@ -14,8 +34,14 @@
</ul>
<div class="tab-content">
<% @heading.ordered_translations.each do |translation| %>
<%= f.fields_for(:translations, translation, :child_index => translation.locale) do |t| %>
<%= render :partial => 'locale_fields', :locals => { :t => t, :locale => translation.locale } %>
<% if translation.locale.to_s == I18n.default_locale.to_s %>
<%= fields_for('public_body_heading', @heading) do |t| %>
<%= render :partial => 'locale_fields', :locals => { :t => t, :locale => translation.locale } %>
<% end %>
<% else %>
<%= f.fields_for(:translations, translation, :child_index => translation.locale) do |t| %>
<%= render :partial => 'locale_fields', :locals => { :t => t, :locale => translation.locale } %>
<% end %>
<% end %>
<% end %>
</div>
Expand Down
6 changes: 6 additions & 0 deletions app/views/admin_public_body_headings/_locale_fields.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,13 @@
<%= t.hidden_field :locale, :value => locale.to_s %>
<label for="<%= form_tag_id(t.object_name, :name, locale) %>" class="control-label">name</label>
<div class="controls">
<% if t.object.errors[:name].any? %>

This comment has been minimized.

Copy link
@crowbot
<span class="fieldWithErrors">
<% end %>
<%= t.text_field :name, :id => form_tag_id(t.object_name, :name, locale), :class => "span4" %>
<% if t.object.errors[:name].any? %>
</span>
<%end %>
</div>
</div>
</div>
4 changes: 2 additions & 2 deletions spec/integration/admin_public_body_heading_edit_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

it 'can edit the default locale' do
@admin.visit edit_admin_heading_path(@heading)
@admin.fill_in 'public_body_heading_translations_attributes_en_name__en', :with => 'New Heading EN'
@admin.fill_in 'public_body_heading_name__en', :with => 'New Heading EN'
@admin.click_button 'Save'

@heading.reload
Expand Down Expand Up @@ -55,4 +55,4 @@
end
end

end
end

0 comments on commit 83a47a9

Please sign in to comment.