Django-crispy-forms: help_text_inline FormHelper does not work as expected

For the following model:

class MyModel(models.Model): name = models.CharField(max_length=110, help_text="Some sample help text.") def __unicode__(self): return u'%s' % (self.name) 

And the following model form:

 class MyModelForm(forms.ModelForm): def __init__(self, *args, **kwargs): super(MyModelForm, self).__init__(*args, **kwargs) self.helper = FormHelper() self.helper.form_id = 'id-myModelForm' self.helper.form_class = 'form-horizontal' self.helper.form_action = 'my_model_form_url' self.helper.form_error_title = 'Form Errors' self.helper.help_text_inline = True class Meta: model = MyModel 

Using the following pattern:

 {% extends "base.html" %} {% block content %} {% load crispy_forms_tags %} {% crispy form %} {% endblock %} 

help_text defined in the model is not displayed at all. It will be displayed if I change to self.helper.help_text_inline = False instead of self.helper.help_text_inline = True , but this is not what I want.

How do I get help_text to display using self.helper.help_text_inline = True ?

In the base.html file, everything loads correctly with the boot files.

+1
source share
1 answer

This is because help_text_inline and error_text_inline cannot be set to the same value to work. If you set help_text_inline to True , you need to set error_text_inline to False . If you do not, help text messages are not displayed to show form errors if they occur.

I have not thought about this in detail so far. Therefore, it would probably be best to add a warning about registration, telling the user to be careful with this. It may automatically override the default behavior of another flag, if set. I am open to suggestions.

+1
source

Source: https://habr.com/ru/post/954944/


All Articles