diff --git a/app/assets/stylesheets/content/_forms.sass b/app/assets/stylesheets/content/_forms.sass index 14fd2a1c00..b1c6e5886e 100644 --- a/app/assets/stylesheets/content/_forms.sass +++ b/app/assets/stylesheets/content/_forms.sass @@ -342,6 +342,17 @@ fieldset.form--fieldset @include grid-size(shrink) max-width: none + &.-error + @extend .icon-error + color: $content-form-danger-zone-bg-color + font-weight: bold + &::before + @include icon-common + display: inline-block + line-height: $base-line-height + padding-right: 0.325rem + + &.-required, .form--field.-required > & &::after diff --git a/lib/tabular_form_builder.rb b/lib/tabular_form_builder.rb index bde5d0bea4..4c8d769bc8 100644 --- a/lib/tabular_form_builder.rb +++ b/lib/tabular_form_builder.rb @@ -198,9 +198,10 @@ class TabularFormBuilder < ActionView::Helpers::FormBuilder id = element_id(translation_form) if translation_form - # FIXME: reenable the error handling - label_options[:class] << 'error' if false && @object && @object.respond_to?(:errors) && @object.errors[field] # FIXME label_options[:class] << 'form--label' + + has_errors = @object.try(:errors) && @object.errors.include?(field) + label_options[:class] << ' -error' if has_errors label_options[:class] << ' -required' if options.delete(:required) label_options[:for] = if options[:for] options[:for] diff --git a/spec/lib/tabular_form_builder_spec.rb b/spec/lib/tabular_form_builder_spec.rb index 0ca04d041f..327bc76b1d 100644 --- a/spec/lib/tabular_form_builder_spec.rb +++ b/spec/lib/tabular_form_builder_spec.rb @@ -582,7 +582,7 @@ JJ Abrams end end - context 'with ActiveModel and withouth specified label' do + context 'with ActiveModel and without specified label' do let(:resource) { FactoryGirl.build_stubbed(:user, firstname: 'JJ', @@ -595,6 +595,18 @@ JJ Abrams it 'uses the human attibute name' do expected_label_like(User.human_attribute_name(:name)) end + + context 'with erroneous field' do + before do + resource.errors.add(:name, :invalid) + end + + it 'shows an appropriate error label' do + expect(output).to have_selector 'label.-error', + count: 1, + text: User.human_attribute_name(:name) + end + end end context 'when required, with a label specified as symbol' do