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
- find even number by Rajeev529 1 week, 5 days ago
- Form field with fixed value by roam 1 month ago
- New Snippet! by Antoliny0919 1 month, 1 week ago
- Add Toggle Switch Widget to Django Forms by OgliariNatan 3 months, 4 weeks ago
- get_object_or_none by azwdevops 7 months, 3 weeks ago
Comments
Please login first before commenting.