Learning how to use custom Form Builders


#1

I worked my way through the FormBuilder example in the Agile Web
Development With Rails book, but I now have some questions about
applying this idea to other situations.

The example seems to work well for the case where I am using form_for
to have a single form with fields that relate to attributes of a
particular model.

How can I use my custom FormBuilder for other situations? Examples:

  1. Non-model fields added to form_for model form.
  2. Fields for other models added using fields_for.
  3. Non-model fields used for non-model forms (just using form_tag)

It seems like the main benefit of using a custom FormBuilder is to
enforce a consistent look across forms. It would be great to extend
this to include all my forms, not just model-based forms.

Thanks!
Errol


#2

On further inspection, it looks like I can specify a builder with
fields_for. That still leaves case #1 and case #3 (see above). Does
anybody have any thoughts on this?


#3

maybe you are right cos django is separate model and form builder


#4

So, has anybody used a custom form builder?


#5

Yes, and its been a big productivity boost once i worked out how to
apply to html wrappers to form fields in the way i wanted. However,
like you, i would like to use if for non-model forms and for
fields_for forms. I haven’t put that high enough on the priority list
to investigate, although i did note that fields_for is in the context
of form_for so I suppose there is some hope there - but I don’t know
how to get under the covers of fields_for.

Cheers, --Kip