Thanks for your help... However, a new problem arised: I want to add
explanatory notes to my form inputs (e.g. "port can be any number from
0 to 65536"), that should be displayed below the caption of the form
field. Does web.form offer any hook to customize the form output in
this way?

On 18 Aug., 03:20, Justin Davis <[EMAIL PROTECTED]> wrote:
> Heh, yes, that'll work too... and indeed the simplest solution is
> often the correct one :)
>
> On Aug 17, 5:27 am, bubblboy <[EMAIL PROTECTED]> wrote:
>
> > Out of pure interest---what is wrong with self.inputs += (new_input,)?
> > Copying to a list and back sounds a little overcomplicated... maybe I'm
> > just missing something, though (didn't read the entire former e-mail).
>
> > b^4
>
> > Justin Davis wrote:
> > > Whoops, rereading this and found a bug in the subclass... appending to
> > > a list doesn't return the list.
>
> > > class DynamicForm(web.form.Form):
>
> > >     def add_input(self, new_input):
> > >         list_inputs = list(self.inputs)
> > >         # Once this is a list, append to it, and cast it back to a
> > > tuple
> > >         list_inputs.append(new_input)
> > >         self.inputs = tuple(list_inputs)
>
> > > On Aug 15, 10:54 pm, Justin Davis <[EMAIL PROTECTED]> wrote:
> > >> It is possible to do this, though perhaps not completely advisable.
> > >> The inputs for a Form object are stored in its "inputs" tuple.  Since
> > >> it's a tuple, unfortunately, you need to replace the entire thing
> > >> since it's immutable.  So, option 1:
>
> > >> x = web.form.Form()
>
> > >> x.inputs = (x.inputs + (web.form.Textbox('mytext'), ) ) # Note we
> > >> force the new input to a tuple so that it gets added correctly
>
> > >> That's a little ugly in my opinion -- what I'd do here is subclass
> > >> web.form.Form, something like this:
>
> > >> class DynamicForm(web.form.Form):
>
> > >>     def add_input(self, new_input):
> > >>         list_inputs = list(self.inputs)
> > >>         # Once this is a list, append to it, and cast it back to a
> > >> tuple
> > >>         self.inputs = tuple(list_inputs.append(new_input))
>
> > >> Then, you can do something like this:
>
> > >> x = DynamicForm()
>
> > >> x.add_input(web.form.Dropdown([1,2,3]))
> > >> x.add_input(web.form.Textbox('foo'))
>
> > >> x.render()
>
> > >> And it should work correctly (note, I haven't tested this code, just
> > >> written it out).  Hope this helps.
>
> > >> Cheers,
> > >> Justin
>
> > >> On Aug 15, 1:21 pm, picurlpy <[EMAIL PROTECTED]> wrote:
>
> > >>> Hi,
> > >>> i want to use web.form to dynamically generate web forms for
> > >>> configuration files. This means that the input elements aren't
> > >>> hardcoded, but should be generated on-demand.
> > >>> Is there a way to dynamically add input elements to a web.form.Form?
> > >>> Something like web.form.Form.add(web.input)
> > >>> The examples I've seen use a predefined number of inputs that are
> > >>> passed at once to web.form.Form. This is not possible in my case.
> > >>> best regards,
> > >>> Franz
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"web.py" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/webpy?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to