kessero
1
I create form filed like this:
header = forms.CharField(
label="Header:",
max_length=TEXT_MAX_SIGNS,
required=False,
widget=forms.Textarea(attrs={"size": TEXT_FILEDS_SIZE}),
)
In html i use tooltips like this
<td><button data-tooltip="text info" data-tooltip-location="top" style="margin:10px" type="button" name="open" id="open" form="form_main2" value="1">Open </button></td>
When user move coursor over button will’se “cloud” with text info
How can I set tooltip text in formfield parameters?
You should be able to make any attribute setting by adding the appropriate entry in the attrs
dict.
kessero
3
I add attrs like this
widget=forms.Textarea(attrs={"size": TEXT_FILEDS_SIZE, "data-tooltip":"text info", "data-tooltip-location":"top"}),
but no luck
What does that end up rendering as the html?
kessero
5
html looks like this
</textarea> </td></tr><tr>
<td><label for="nazwa">Header:</label>
<td><textarea name="header" cols="40" rows="10" size="50" data-tooltip="text info" data-tooltip-location="top" maxlength="500" id="id_header">
default header
</textarea> </td></tr>
So yes, it looks like those attributes are being applied to the widget.
kessero
7
I make small experiment:
my html fragment befor:
<form action="/settings/" method="post" id="form1">
{% csrf_token %}
<table id="table" class="table table-striped table-responsive-md">
{% for field in form_main_settings %}
<tr>
<td><label for="nazwa">{{field.label}}</label>
<td >{{field}} {{field.help_text}}</td>
</tr>
{%endfor%}
my html fragment with tooltip added in html:
<form action="/settings/" method="post" id="form1">
{% csrf_token %}
<table id="table" class="table table-striped table-responsive-md">
{% for field in form_main_settings %}
<tr>
<td><label for="nazwa">{{field.label}}</label>
<td data-tooltip="test text"
data-tooltip-location="top">{{field}} {{field.help_text}}</td>
</tr>
{%endfor%}
this works so problem is after generate tooltip from form.py how can i access from form field to atrrs?
I figure out that if i add in html textarea with tooltip:
<tr>
<td><label for="nazwa">{{field.label}}</label>
<td>{{field}} {{field.help_text}}</td>
**<td><textarea data-tooltip="text info" data-tooltip-location="top"> test</textarea></td>**
</tr>
It doesn’t show up. It look like textarea don’t work with tooltip. If i change
<textarea> to <p>
it works.
kessero
8
For future some workaround of my problem. Areatext has title=“some tooltip” attrs with basically works similar for tooltips
widget=forms.Textarea(attrs={"size": TEXT_FILEDS_SIZE, "title":"text as tooltip"})