Skip to content

Commit

Permalink
Fix form-range class
Browse files Browse the repository at this point in the history
  • Loading branch information
lcreid committed Jun 10, 2024
1 parent b1ebbdf commit dcd3af0
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
5 changes: 3 additions & 2 deletions lib/bootstrap_form/inputs/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ module Base
extend ActiveSupport::Concern

class_methods do
def bootstrap_field(field_name, control_class: nil)
define_method :"#{field_name}_with_bootstrap" do |name, options={ control_class: control_class }.compact|
def bootstrap_field(field_name)
define_method :"#{field_name}_with_bootstrap" do |name, options={}|
warn_deprecated_layout_value(options)
options = options.reverse_merge(control_class: "form-range") if field_name == :range_field
form_group_builder(name, options) do
prepend_and_append_input(name, options) do
options[:placeholder] ||= name if options[:floating]
Expand Down
2 changes: 1 addition & 1 deletion lib/bootstrap_form/inputs/range_field.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module RangeField
include Base

included do
bootstrap_field :range_field, control_class: "form-range"
bootstrap_field :range_field
end
end
end
Expand Down
10 changes: 10 additions & 0 deletions test/bootstrap_fields_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,16 @@ class BootstrapFieldsTest < ActionView::TestCase
assert_equivalent_html expected, @builder.range_field(:misc)
end

test "range fields are wrapped correctly with exta attributes" do
expected = <<~HTML
<div class="mb-3">
<label class="form-label" for="user_misc">Misc</label>
<input min="0" max="80" class="form-range" id="user_misc" name="user[misc]" type="range" />
</div>
HTML
assert_equivalent_html expected, @builder.range_field(:misc, min: 0, max: 80)
end

test "search fields are wrapped correctly" do
expected = <<~HTML
<div class="mb-3">
Expand Down

0 comments on commit dcd3af0

Please sign in to comment.