Monday, February 26, 2018

Re: Trying to use tooltips in django 2.0 form



On Mon, Feb 26, 2018 at 9:16 AM, Alan <alanwilter@gmail.com> wrote:
Hi there,

I have this in my forms.py:

class SubmissionForm(forms.Form):


    molecule_file = forms.FileField(validators=[FileExtensionValidator(settings.CONTENT_TYPES), file_size], help_text="Required: Select a PDB, MDL or MOL2 file")


But I am failing to make it work in my submit.html template. Currently, I am "hacking" with:

<p title="Required: Select a PDB, MDL or MOL2 file."><label>{{form.molecule_file.label}}</label>{{ form.molecule_file }}</p>


That will show the tooltip "Required: Sel..." if mouse pause over this field in the browser, but this is silly, I wish I could use something like:

<p title={{form.molecule_file.help_text}}><label>{{form.molecule_file.label}}</label>{{ form.molecule_file }}</p>


But that is not working, neither any combination I tried with .title etc.

Any suggestion would be very much appreciated.

Many thanks in advance,

Alan

Alan,

The use of "help_text" in a template is shown here:

That is an example of how you should render a form field "manually". You may also try seeing the output of {{ form.as_p }} and then tweak it to your needs (you can use that in whatever tooltip wrapper - like bootstrap or other css frameworks).
 
HTH!

-- 
I'll cycle across Britain in 2018 for a charity, would you consider
Many thanks!
--
Alan Wilter SOUSA da SILVA, DSc
Senior Bioinformatician, UniProt
European Bioinformatics Institute (EMBL-EBI)
European Molecular Biology Laboratory
Wellcome Trust Genome Campus
Hinxton
Cambridge CB10 1SD
United Kingdom
Tel: +44 (0)1223 494588

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAEznbzmoK07JfXPp_MOvmYFe84a%3D5YiBQMEFJOtUsUzpjPjTGg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CA%2BFDnhJROhWhC8mMx2ycsVX2m37rRyaXR_Mg3EALJfZhFFskJQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment