Question

I have a form that accepts a list of strings :

class MyForm(Form):
    __orders__ = None
    order_by = FieldList(StringField('order_by'))

And here's my view :

@app.route("/")
def my_view():
    form = MyForm(request.args)
    print form.order_by.entries

I tried to request the url with :

/?order_by=hello&order_by=world
/?order_by[]=hello&order_by[]=world
/?order_by%5B%5D=hello&order_by%5B%5D=world

form.order_by.entries is always empty ([])

What am I missing ?

Was it helpful?

Solution

Ok here's how I did, using SelectMultipleField, but without having to deal with choices :

class MultipleTextField(SelectMultipleField):
    """
    No different from a normal select field, except this one can take (and
    validate) multiple choices.  You'll need to specify the HTML `rows`
    attribute to the select field when rendering.
    """
    widget = widgets.Select(multiple=True)
    coerce = str
    choices = []

    def pre_validate(self, form):
        pass

OTHER TIPS

I haven't tested this, but looking at the source code it seems this might work:

/?order_by-0=hello&order_by-1=world
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top