Login

Help text hyperlinks

Author:
sa2812
Posted:
April 28, 2023
Language:
Python
Version:
3.2
Score:
1 (after 1 ratings)

Sometimes a plain-text help-text isn't sufficient, and it's handy to be able to add links to pages, documentation or external websites.

This javascript snippet can be added to your page, in combination with adding a class to your help text in your template. This assumes you're using jQuery on your website.

Field template snippet:

{% if field.help_text %}<p class="help-text">{{ field.help_text }}</p>{% endif %}

On document ready, this will convert the markdown-style links into anchor tags, allowing you to have richer help text for your users

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
{% block body_js %}
<script>
  $(document).ready(function() {
    var helpTexts = $('.help-text');
    $.each(helpTexts, (i, helpText) => {
      $(helpText).html($(helpText).text().replace(/\[([\w\s\d]+)\]\((https?:\/\/[\w\d./?=#]+)\)/, '<a href="$2" target="_blank">$1</a>'))
    });
  });
</script>
{% endblock %}

More like this

  1. Image compression before saving the new model / work with JPG, PNG by Schleidens 4 days, 19 hours ago
  2. Stuff by NixonDash 3 months, 1 week ago
  3. Add custom fields to the built-in Group model by jmoppel 5 months, 1 week ago
  4. Month / Year SelectDateWidget based on django SelectDateWidget by pierreben 8 months, 3 weeks ago
  5. Python Django CRUD Example Tutorial by tuts_station 9 months, 1 week ago

Comments

Please login first before commenting.