Skip to content
This repository has been archived by the owner on Oct 17, 2023. It is now read-only.

Commit

Permalink
Fix bug when field errors is an empty array
Browse files Browse the repository at this point in the history
  • Loading branch information
westonganger committed Mar 25, 2023
1 parent b5591bd commit ca4ff3f
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ CHANGELOG
- **Unreleased**
- [View Diff](https://github.com/westonganger/sexy_form.rb/compare/v0.9.0...master)
- [#2](https://github.com/westonganger/sexy_form.rb/pulls/2) - Remove validations on field `:type` option
- Fix bug when field `:errors` is provided but is empty

- **0.9.0** - February 15, 2019
- Gem Initial Release
2 changes: 1 addition & 1 deletion lib/sexy_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

### Require all themes
require "sexy_form/themes/base_theme"
Dir[File.join(__dir__, "sexy_form/themes/*.rb")].each do |f|
Dir[File.join(__dir__, "sexy_form/themes/*.rb")].each do |f|
require "sexy_form/themes/#{f.split("/").last}"
end

Expand Down
2 changes: 1 addition & 1 deletion lib/sexy_form/builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def field(
end
end

if errors.nil?
if errors
html_errors = errors.map{|x|
@theme.build_html_error(error: x, field_type: type, html_attrs: SexyForm.safe_string_hash(errors))
}
Expand Down
4 changes: 4 additions & 0 deletions spec/sexy_form/builder_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@
builder.field(type: "submit", name: :foobar)
end

it "doesnt fail when errors is empty" do
expect(builder.field(type: :text, label: false, name: "my-great-text-input", errors: [])).to eq("<div><input type=\"text\" name=\"my-great-text-input\" id=\"my-great-text-input\"></div>")
end

describe "input fields" do
(TESTED_FIELD_TYPES - SexyForm::Builder::NON_INPUT_TYPES).each do |field_type|

Expand Down

0 comments on commit ca4ff3f

Please sign in to comment.