Document adding a field dynamically
@gawel is already working on this.
Since Jul 14, 2018.
- Dominant language
- Python
- Stars
- 346
- Forks
- 113
- PR merge metrics
- No merged PRs in 30d
Description
In this use case, we are implementing a checkbox/chevron kind of widget, for this we're adding new fields dynamically (with javascript) if they don't yet exist.
While testing this field, we had to add the checkboxes manually in order to be able to submit it. However, we have not found any mention of this in the docs; did we miss it, or is it not documented?
A bit of googling brought us to this SO answer (quoted below), and it seemed to work well for us, except we also had to add the pos argument. Is this the suggested way to do this? Would you appreciate a PR to document this use case?
from webtest.forms import Checkbox
def add_dynamic_checkbox_field(form, name, value):
""" Add an extra checkbox field to a form. """
field = Checkbox(form, 'input', None, 1, value)
form.fields[name] = [field]
form.field_order.append((name, field))
# usage:
add_dynamic_checkbox_field(resp.form, 'new_field_name', 'some_value')
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.