I have a form, wich all the fields have a “help_text”.. “provide your username”, “your name here!”, etc.
What I wanted to do, is when the form is submitted and the value wasn’t provided, to show an error in that
Example without submitting (in the template):
{{ userForm.username }}
<span class="helptext">{{ userForm.username.help_text }}</span>
If the form is submitted and the value is “empty”, then it would show in error_messages the required key, in this case “This field is required”, but I want to add an extra class to the span if the error type is required.
So, expample when the user submits the form with an empty value:
{{ userForm.username }}
<span class="helptext{% if userForm.username.errors.required %} required{% endif %}">{{ userForm.username.help_text }}</span>
Or something like that, hope you understand guys, thanks!
This should be doable using:
and
Check this post for some general infos on this.