One purpose of formwandler is to take the form logic out of the HTML template. Right now you can configure most of the relevant attributes of fields (like hidden and disabled) in the form class, but you have to make sure yourself that these settings are reflected in the template, which is not DRY.
Currently, the template code for a field that may be hidden or disabled in some cases may look like this:
class MyForm < Formwandler::Form
field :my_field, model: :my_model, hidden: -> { no_admin? }, disabled: -> { no_admin? || unconfirmed? }, default: -> { controller.current_user.middle_name }
private
def no_admin?
!controller.current_user.admin?
end
def unconfirmed?
!controller.current_user.confirmed?
end
end
What I want is a helper method that does this redundant work for me. If possible, it should even render the whole form with one call. Of course, there are some more things to consider:
The form class does currently not know the types of the fields. To correctly produce, e.g., the above call to f.text_field, this information has to be provided somehow.
Usually the template for the form contains custom HTML and CSS classes so that providing the above "naked" default variant will be useless in most cases.
Even worse, the custom HTML/CSS may differ for various field types. You usually build a checkbox quite differently than a number field.
One purpose of formwandler is to take the form logic out of the HTML template. Right now you can configure most of the relevant attributes of fields (like
hidden
anddisabled
) in the form class, but you have to make sure yourself that these settings are reflected in the template, which is not DRY.Currently, the template code for a field that may be hidden or disabled in some cases may look like this:
What I want is a helper method that does this redundant work for me. If possible, it should even render the whole form with one call. Of course, there are some more things to consider:
f.text_field
, this information has to be provided somehow.