I needed to manipulate form (add new input element) after creation but
couldn't find a way in Form class.
Scenario:
You have categories and put them in a form as checkbox. Here is the form:
categoryForm = form.Form(
> form.Textbox("header",
> form.notnull,
> description = "Header",
> ),
--other inputs--
> )
>
We had categories from db.
categories = [["1","Python"],["2","Js"],["3","Html"]]
>
> for id, name in categories:
> chk = form.Checkbox('categories',
> value = id,
> description = net.websafe(name)
> )
> categoryForm.add_input(chk)
>
Thu usage is above, i defined "add_input" function in Form.py, it takes an
Input object and index, if index is not given the Input will be append to
the form (as last element).
Here is the add_input function:
def add_input(self, input, index = None):
> """appends or inserts inputs to the form, if index is given then
> the
> the input will be insert with the given index, if not the input
> will
> be append to the self.inputs tuple"""
> self.inputs = list(self.inputs)
> if not index and index != 0:
> self.inputs.append(input)
> else:
> self.inputs.insert(index, input)
>
> self.inputs = tuple(self.inputs)
>
And here is the patch:
*** 109,114 ****
> --- 109,126 ----
> return utils.storage([(i.name, i.get_value()) for i in
> self.inputs])
> d = property(_get_d)
>
> + def add_input(self, input, index = None):
> + """appends or inserts inputs to the form, if index is given then
> the
> + the input will be insert with the given index, if not the input
> will
> + be append to the self.inputs tuple"""
> + self.inputs = list(self.inputs)
> + if not index and index != 0:
> + self.inputs.append(input)
> + else:
> + self.inputs.insert(index, input)
> +
> + self.inputs = tuple(self.inputs)
> +
> class Input(object):
> def __init__(self, name, *validators, **attrs):
> self.name = name
>
--
Aydın ŞEN
--
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.