Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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