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
6 changes: 1 addition & 5 deletions app/components/flowbite/input/validation_error.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,8 @@
module Flowbite
module Input
class ValidationError < ViewComponent::Base
def initialize(message:)
@message = message
end

def call
tag.p(@message, class: "mt-2 text-sm text-red-600 dark:text-red-500")
tag.p(content, class: "mt-2 text-sm text-red-600 dark:text-red-500")
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion app/components/flowbite/input_field/checkbox.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@
</div>

<% errors.each do |error| %>
<%= render(Flowbite::Input::ValidationError.new(:message => error.upcase_first)) %>
<%= render(Flowbite::Input::ValidationError.new) { error.upcase_first } %>
<% end %>
</div>
2 changes: 1 addition & 1 deletion app/components/flowbite/input_field/input_field.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
<%= input %>
<%= hint %>
<% errors.each do |error| %>
<%= render(Flowbite::Input::ValidationError.new(:message => error.upcase_first)) %>
<%= render(Flowbite::Input::ValidationError.new) { error.upcase_first } %>
<% end %>
</div>
2 changes: 1 addition & 1 deletion app/components/flowbite/input_field/radio_button.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@
</div>

<% errors.each do |error| %>
<%= render(Flowbite::Input::ValidationError.new(:message => error.upcase_first)) %>
<%= render(Flowbite::Input::ValidationError.new) { error.upcase_first } %>
<% end %>
</div>
8 changes: 4 additions & 4 deletions test/components/input/validation_error_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,27 @@ class Flowbite::Input::ValidationErrorTest < Minitest::Test
include ViewComponent::TestHelpers

def test_renders_validation_error_message
render_inline(Flowbite::Input::ValidationError.new(message: "This field is required"))
render_inline(Flowbite::Input::ValidationError.new) { "This field is required" }

assert_selector("p.mt-2.text-sm.text-red-600.dark\\:text-red-500", text: "This field is required")
end

def test_renders_with_empty_message
render_inline(Flowbite::Input::ValidationError.new(message: ""))
render_inline(Flowbite::Input::ValidationError.new) { "" }

assert_selector("p.mt-2.text-sm.text-red-600.dark\\:text-red-500", text: "")
end

def test_renders_with_html_escaped_message
render_inline(Flowbite::Input::ValidationError.new(message: "Field must be <strong>valid</strong>"))
render_inline(Flowbite::Input::ValidationError.new) { "Field must be <strong>valid</strong>" }

assert_selector("p.mt-2.text-sm.text-red-600.dark\\:text-red-500", text: "Field must be <strong>valid</strong>")
refute_selector("p strong")
end

def test_renders_with_multiline_message
message = "This field has multiple validation errors:\n- Cannot be blank\n- Must be at least 5 characters"
render_inline(Flowbite::Input::ValidationError.new(message: message))
render_inline(Flowbite::Input::ValidationError.new) { message }

assert_selector("p.mt-2.text-sm.text-red-600.dark\\:text-red-500", text: message)
end
Expand Down