Skip to content

Commit

Permalink
Merge pull request #2373 from dalpo/fix/browser_validations
Browse files Browse the repository at this point in the history
Fix: novalidate attribute merging
  • Loading branch information
mshibuya committed Aug 10, 2015
2 parents 5b2aa86 + 21660c1 commit 4ee05f1
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
10 changes: 4 additions & 6 deletions app/helpers/rails_admin/main_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,18 @@
module RailsAdmin
module MainHelper
def rails_admin_form_for(*args, &block)
options = args.extract_options!.reverse_merge(
html: {novalidate: !RailsAdmin::Config.browser_validations},
builder: RailsAdmin::FormBuilder,
)
options = args.extract_options!.reverse_merge(builder: RailsAdmin::FormBuilder)
(options[:html] ||= {})[:novalidate] ||= !RailsAdmin::Config.browser_validations

form_for(*(args << options), &block) << after_nested_form_callbacks
end

def get_indicator(percent)
return '' if percent < 0 # none
return 'info' if percent < 34 # < 1/100 of max
return 'info' if percent < 34 # < 1/100 of max
return 'success' if percent < 67 # < 1/10 of max
return 'warning' if percent < 84 # < 1/3 of max
'danger' # > 1/3 of max
'danger' # > 1/3 of max
end

def get_column_sets(properties)
Expand Down
8 changes: 8 additions & 0 deletions spec/helpers/rails_admin/main_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
helper.rails_admin_form_for(FieldTest.new, url: new_path(model_name: 'field_test')) {}
end

let(:html_form_with_attrs) do
helper.rails_admin_form_for(FieldTest.new, url: new_path(model_name: 'field_test'), html: {class: 'example'}) {}
end

context 'with html5 browser_validations enabled' do
before do
RailsAdmin.config.browser_validations = true
Expand Down Expand Up @@ -34,6 +38,10 @@
it 'should add novalidate attribute to the html form tag' do
expect(html_form).to include "novalidate=\"novalidate\""
end

it 'should add novalidate attribute to the html form tag with html attributes' do
expect(html_form_with_attrs).to include "novalidate=\"novalidate\""
end
end
end
end

0 comments on commit 4ee05f1

Please sign in to comment.