On Sun, Aug 1, 2010 at 9:20 AM, Neveen Adel <[email protected]> wrote:

> Hello,
>
> i have function for example
> def form_1():
>  form =  SQLFORM (_name='form_1')
>
> and i want inside a different function to load this form and insert
> element into it
>
> For example:
>
>  def another_fn(form_name):
>    form = # load the form by form Name
>    #and then do
>   form[0].element().insert() ....
>
>
> Is that valid or not ?
>
> Yes. But you must return form is the creation function, such as:

def reusable_form(maybe_some_args, make_it_more, reusable=True):
    form = SQLFORM(maybe_some_args, are_used_here)
    # maybe other args can be used for some form manipulation (adding
buttons, changing layout)
    return form # this is necessary

Then you can reuse the form at will.
By the way. You don't need to pass the form as an argument, because it will
be available in the context.

Then there is the question of where to store these pre-built forms. In
general I tend to create a model file exclusively  for reusable forms.

Miguel

Reply via email to