Skip to content

Commit

Permalink
fixup! 03efb25 Better validation highlighting
Browse files Browse the repository at this point in the history
  • Loading branch information
garethrees committed Mar 6, 2015
1 parent dcd6896 commit 9e1bd38
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
11 changes: 8 additions & 3 deletions app/views/admin_public_body_categories/_form.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

<% if @category.errors.any? %>
<ul>
<% @category.errors.each do |attr, message| %>
Expand Down Expand Up @@ -35,8 +34,14 @@

<div class="tab-content">
<% @category.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_category', @category) 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
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,23 @@
<%= t.hidden_field :locale, :value => locale.to_s %>
<label for="<%= form_tag_id(t.object_name, :title, locale) %>" class="control-label">Title</label>
<div class="controls">
<% if locale == I18n.default_locale && t.object.errors[:title].any? %>
<% if t.object.errors[:title].any? %>

This comment has been minimized.

Copy link
@crowbot

crowbot Mar 10, 2015

Member

These if statements aren't needed at all anymore, I don't think. As we're using the translations or the main object, the built-in error highlighting works.

<span class="fieldWithErrors">
<% end %>
<%= t.text_field :title, :id => form_tag_id(t.object_name, :title, locale), :class => "span4" %>
<% if locale == I18n.default_locale && t.object.errors[:title].any? %>
<% if t.object.errors[:title].any? %>
</span>
<%end %>
</div>
</div>
<div class="control-group">
<label for="<%= form_tag_id(t.object_name, :description, locale) %>" class="control-label">Description</label>
<div class="controls">
<% if locale == I18n.default_locale && t.object.errors[:description].any? %>
<% if t.object.errors[:description].any? %>

This comment has been minimized.

Copy link
@crowbot

crowbot Mar 10, 2015

Member
<span class="fieldWithErrors">
<% end %>
<%= t.text_field :description, :id => form_tag_id(t.object_name, :description, locale), :class => "span4" %>
<% if locale == I18n.default_locale && t.object.errors[:description].any? %>
<% if t.object.errors[:description].any? %>
</span>
<%end %>
</div>
Expand Down
2 changes: 1 addition & 1 deletion spec/integration/admin_public_body_category_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_category_path(@category)
@admin.fill_in 'public_body_category_translations_attributes_en_title__en', :with => 'New Category EN'
@admin.fill_in 'public_body_category_title__en', :with => 'New Category EN'
@admin.click_button 'Save'

@category.reload
Expand Down

0 comments on commit 9e1bd38

Please sign in to comment.