diff --git a/app/views/rails_admin/main/_form_field.html.haml b/app/views/rails_admin/main/_form_field.html.haml index 3118b5e42f..df9714826a 100644 --- a/app/views/rails_admin/main/_form_field.html.haml +++ b/app/views/rails_admin/main/_form_field.html.haml @@ -1 +1 @@ -= form.send field.view_helper, field.method_name, field.html_attributes.reverse_merge({ value: field.form_value, checked: field.form_value.in?([true, '1']), class: 'form-control'}) += form.send field.view_helper, field.method_name, field.html_attributes.reverse_merge({ value: field.form_value, checked: field.form_value.in?([true, '1']), class: 'form-control', required: field.required}) diff --git a/app/views/rails_admin/main/_form_text.html.haml b/app/views/rails_admin/main/_form_text.html.haml index 87ad034532..fafc9b9b50 100644 --- a/app/views/rails_admin/main/_form_text.html.haml +++ b/app/views/rails_admin/main/_form_text.html.haml @@ -1 +1 @@ -= form.text_area field.method_name, field.html_attributes.reverse_merge(data: { richtext: false, options: {}.to_json }).reverse_merge({ value: field.form_value, class: 'form-control' }) += form.text_area field.method_name, field.html_attributes.reverse_merge(data: { richtext: false, options: {}.to_json }).reverse_merge({ value: field.form_value, class: 'form-control', required: field.required }) diff --git a/spec/integration/basic/edit/rails_admin_basic_edit_spec.rb b/spec/integration/basic/edit/rails_admin_basic_edit_spec.rb index 0ba0b01266..91eeb06c95 100644 --- a/spec/integration/basic/edit/rails_admin_basic_edit_spec.rb +++ b/spec/integration/basic/edit/rails_admin_basic_edit_spec.rb @@ -23,6 +23,15 @@ expect(find('#player_born_on_field .help-block')).to have_content('Optional') expect(find('#player_notes_field .help-block')).to have_content('Optional') end + + it "checks required fields to have required attribute set" do + expect(find_field("player_name")[:required].nil?).to eq(false) + expect(find_field("player_number")[:required].nil?).to eq(false) + end + + it "checks optional fields to not have required attribute set" do + expect(find_field("player_position")[:required].nil?).to eq(true) + end end describe 'association with inverse_of option' do