1

This answer addresses what I'm trying to accomplish: Post the checkboxes that are unchecked

Given the following form fields:

auto = BooleanField('Is autonomous working?', default=False)
beacon = BooleanField('Can it push the beacon?', default=False)

I get a 400 bad request as I am trying to get data from the form in my view that isn't there because the POST doesn't send the boolean field data when the box is unchecked (False)

Looking at the appropriate way to handle this with wtforms and am having trouble finding a solution. Thanks for any insight.

Community
  • 1
  • 1
Jason Rahm
  • 670
  • 3
  • 14
  • Your question is unclear. If your question is "how will I know if a `BooleanField` is unchecked, the answer is that its data will be `False` when you access it. – jumbopap Dec 29 '15 at 22:23
  • i thought it was pretty clear in the link I provided and didn't find it necessary to reproduce the text. I'll be more thorough in the future. – Jason Rahm Dec 30 '15 at 04:36
  • Possible duplicate of [Post the checkboxes that are unchecked](http://stackoverflow.com/questions/1809494/post-the-checkboxes-that-are-unchecked) – Crast Jan 03 '16 at 19:15

1 Answers1

2

I found the answer after modifying my search parameters. Already answered here: BooleanField usage in WTForms - 400 Bad Request

The actual answer code that helped me is this:

if 'base_select' in request.form:
        create_base = 'y'
    else:
        create_base = 'n'

This checks the form to make sure the field was submitted before trying to extract value from it. Hope this helps someone in the future.

Community
  • 1
  • 1
Jason Rahm
  • 670
  • 3
  • 14
  • 1
    Sounds like they did find an answer. As the question was already asked and answered before, perhaps it should be closed as a duplicate. – Leigh Dec 29 '15 at 23:18
  • done. Still relatively new to Stack, thanks for the guidance. – Jason Rahm Dec 30 '15 at 04:39