question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cannot set Field to type='hidden' in FormHelper

See original GitHub issue

I have a formset and a formhelp object.

class MyHelper(FormHelper):
         def __init__(self, *args, **kwargs):
             super(MyHelper, self).__init__(*args, **kwargs)
             self.helper = FormHelper()
             self.layout = Layout(
                 Field('set_id', type='hidden', value='0')
             )

When I render this formset, I get this error:

can't set attribute

The line that causes this error is:

/Users/cheng/.virtualenvs/waimai/lib/python2.7/site-packages/crispy_forms/utils.py in render_field
92.                                        field_instance.widget.is_hidden = True 

When I remove the type=‘hidden’ part from the Field definition, everything works. I don’t know why I cannot set this field to hidden. Here is the model definition of this field:

class Answer(models.Model):
    set_id = models.IntegerField()

Thanks for your help!

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:8

github_iconTop GitHub Comments

4reactions
kviktorcommented, Jun 19, 2015

Any ETA for PyPI release?

0reactions
squ1b3rcommented, Jun 23, 2017

Is this ever going to be released? It’s sitting in the dev branch for two years now.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Django crispy forms - Set hidden field value - Stack Overflow
The code is working, but I want to set the value of the hidden TEMPLATE field to "VALUE" when the form is submitted....
Read more >
FormHelper - 2.x - CakePHP Cookbook
Since this is an edit form, a hidden input field is generated to override the default HTTP method. When creating forms for models...
Read more >
ActionView::Helpers::FormHelper - Rails API
This way, the client either sends only the hidden field (representing the check box is unchecked), or both fields. Since the HTML specification...
Read more >
Layouts — django-crispy-forms 1.14.0 documentation
This allows you to set the order of the fields, wrap them in divs or other ... If you want to render a...
Read more >
form_for (ActionView::Helpers::FormHelper) - APIdock
:enforce_utf8 - If set to false, a hidden input with name utf8 is not output. :html - Optional HTML attributes for the form...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found