Can I use the information in the schema e.g. to set up a form view with matching controls?
As an example, if I had this schema:
Form = Dry::Validation.Form do
required(:name).filled(:str?)
end
And wanted to do this in a view:
<input type="#{input_type(:name)}" required="#{check_required(:name)}">
Could I query the schema from input_type
and check_required
?
I’m looking for something similar to this:
def input_type(attr)
case Form.some_method[attr].some_method_to_get_type
when :string then "text"
# ...
end
end
def check_required(attr)
if Form.some_method[attr].some_method_to_check_if_required?
"required"
else
""
end
end