Add HelpTextField widget
This commit is contained in:
parent
dd30906971
commit
d9ae9e4b22
2 changed files with 29 additions and 0 deletions
26
pinaxcon/proposals/fields.py
Normal file
26
pinaxcon/proposals/fields.py
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
from django import forms
|
||||||
|
|
||||||
|
|
||||||
|
class HelpTextWidget(forms.Widget):
|
||||||
|
template_name = "forms/widgets/help_widget.html"
|
||||||
|
|
||||||
|
def __init__(self, *args, text=None, **kwargs):
|
||||||
|
super().__init__(*args, **kwargs)
|
||||||
|
self.text = text
|
||||||
|
|
||||||
|
def render(self, name, value, attrs=None, renderer=None):
|
||||||
|
context = {'text': self.text}
|
||||||
|
return self._render(self.template_name, context, renderer)
|
||||||
|
|
||||||
|
|
||||||
|
class HelpTextField(forms.Field):
|
||||||
|
def __init__(self, *args, text=None, **kwargs):
|
||||||
|
super().__init__(self, *args, **kwargs)
|
||||||
|
self.required = False
|
||||||
|
|
||||||
|
widget = HelpTextWidget(text=text)
|
||||||
|
widget.is_required = False
|
||||||
|
self.widget = widget
|
||||||
|
|
||||||
|
def clean(self, value):
|
||||||
|
return value
|
3
pinaxcon/templates/forms/widgets/help_widget.html
Normal file
3
pinaxcon/templates/forms/widgets/help_widget.html
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
<div>
|
||||||
|
<p>{{ text|safe }}</p>
|
||||||
|
</div>
|
Loading…
Reference in a new issue