Skip to content

Commit 7068b96

Browse files
committed
Add errors and valid/invalid to Rails::Field
1 parent d2c09e6 commit 7068b96

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

lib/superform/rails/field.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,18 @@ def select(*collection, **attributes, &)
4949
Components::Select.new(field, attributes:, collection:, &)
5050
end
5151

52+
def errors
53+
object.errors[key]
54+
end
55+
56+
def invalid?
57+
errors.any?
58+
end
59+
60+
def valid?
61+
not invalid?
62+
end
63+
5264
# HTML5 input type convenience methods - clean API without _field suffix
5365
# Examples:
5466
# field(:email).email(class: "form-input")

0 commit comments

Comments
 (0)