Skip to content

Commit

Permalink
Fixed bug causing input group wrapper to always show even if options …
Browse files Browse the repository at this point in the history
…are not available
  • Loading branch information
shivam091 committed May 15, 2023
1 parent a1fc596 commit 20f8c83
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions lib/rails_bootstrap_form/input_group_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,17 @@ def self.included(base_class)
def input_group_wrapper(attribute, bootstrap_options, &block)
input = capture(&block) || ActiveSupport::SafeBuffer.new

prepend = attach_input(bootstrap_options, :prepend)
append = attach_input(bootstrap_options, :append)
if input_group_required?(bootstrap_options)
prepend = attach_input(bootstrap_options, :prepend)
append = attach_input(bootstrap_options, :append)

input = prepend + input + append
input += generate_error(attribute)
input = prepend + input + append
input += generate_error(attribute)

input = tag.div(input, class: input_group_classes(attribute, bootstrap_options))
input = tag.div(input, class: input_group_classes(attribute, bootstrap_options))
else
input += generate_error(attribute)
end

input
end
Expand All @@ -42,8 +46,15 @@ def input_group_content(content)
tag.span(content.html_safe, class: "input-group-text")
end

def input_group_required?(bootstrap_options)
[
bootstrap_options.prepend,
bootstrap_options.append
].any?(&:present?)
end

private :input_group_wrapper, :input_group_classes, :attach_input,
:input_group_content
:input_group_content, :input_group_required?
end
end
end

0 comments on commit 20f8c83

Please sign in to comment.