python - Why is my WTForm HiddenField not being set to a default value? -
i have employeeform
1 of fields comprising of photoform
shown below:
class employeeform(form): name = stringfield('full name', validators=[datarequired()]) title = stringfield('job title', validators=[datarequired()]) email = stringfield('company email', validators=[datarequired()]) department = stringfield('department', validators=[datarequired()]) photo = formfield(photoform)
depending on whether use_s3
config variable set true
or false
want 2 fields on photo object automatically set default values so:
class photoform(form): image = s3imageuploadfield(base_path=app.config['upload_folder'],namegen=photo_name_generator) if app.config['use_s3']: image_storage_type = hiddenfield('s3') image_storage_bucket_name = hiddenfield(app.config['s3_bucket_name']) else: image_storage_type = hiddenfield('empty string') image_storage_bucket_name = hiddenfield('empty string')
however, when check form's html there no hidden field nor when check database on submission there set values on image_storage_type
, image_bucket_name
, can't figure out why is. i've checked on stackoverflow questions don't fit question because using flask-admin
, wtform
in opinion makes little more trickier.
also, admin.py
file form rendering looks this:
class employeeview(modelview): form = employeeform
i'm not sure if problem on wtform's side or flask-admin's side i've been trying long time make work. has ideas? appreciated.
the first argument field label. in code aren't passing data field, setting label. set default data default
kwarg.
from wtforms import form, hiddenfield class photoform(form): default_image_data = "foo" if true else "bar" image_storage_type = hiddenfield('image storage', default=default_image_data) >>> form = photoform() >>> form.image_storage_type.data 'foo' >>> form.image_storage_type() u'<input id="image_storage_type" name="image_storage_type" type="hidden" value="foo">'
Comments
Post a Comment