[Flask] Form with no validators failing validation

Alex Hall ahall at autodist.com
Tue Apr 26 09:11:32 EDT 2016


Final follow-up: I got it. I thought the first string passed to the
constructor of the field gave it its ID, but the ID comes from the variable
name (a neat trick). The string is the label text I want, explaining the
multiple keywords error. You can disregard this thread, and sorry for the
traffic.

On Tue, Apr 26, 2016 at 9:04 AM, Alex Hall <ahall at autodist.com> wrote:

> Just a follow-up: I forgot to say that I also tried
>
>  myField = StringField("myField", validators=[Optional()], label="my label
> text goes here")
>
> and gotten the error:
> TypeError: __init__() got multiple values for keyword argument 'label'
>
> As I said, I'm sure there's an easy way to do this, I just haven't found
> it.
>
> On Tue, Apr 26, 2016 at 8:44 AM, Alex Hall <ahall at autodist.com> wrote:
>
>> In the form class, simply put
>>  myField.label.text = "some label text"
>>
>> Right away, Flask errors out:
>> AttributeError: 'UnboundField' object has no attribute 'label'
>>
>> That's why I assumed I had to do it after instantiating the form. I even
>> tried putting all my class properties in __init__, assigning them all to
>> self (self.myField = StringField()), and then using
>> self.myField.label.text, but I got the same error. The only difference is
>> that the error shows on the webpage rather than in the command line. As
>> usual, I'm probably missing something obvious. :)
>>
>> On Tue, Apr 26, 2016 at 3:08 AM, Andrea D'Amore <and.damore at gmail.com>
>> wrote:
>>
>>> On 25 April 2016 at 22:01, Alex Hall <ahall at autodist.com> wrote:
>>> > Because it worked.  I know there must be an easier way,
>>>
>>> I'd say in the form definition, as you are already doing with
>>> placeholders.
>>>
>>> > but I couldn't set it right in the form class as the properties didn't
>>> exist yet and so lacked the label property.
>>>
>>> Can you provide a SSCCE (short self-contained correct example [1] -
>>> this definitely needs a better name…) of this issue?
>>>
>>> [1]: http://sscce.org
>>>
>>> --
>>> Andrea
>>>
>>
>>
>>
>> --
>> Alex Hall
>> Automatic Distributors, IT department
>> ahall at autodist.com
>>
>
>
>
> --
> Alex Hall
> Automatic Distributors, IT department
> ahall at autodist.com
>



-- 
Alex Hall
Automatic Distributors, IT department
ahall at autodist.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/flask/attachments/20160426/14ebb8e4/attachment.html>


More information about the Flask mailing list