Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

remove (* char) from the required field label in form

I'm trying to change the label of the fields that are required in django form using labels in Meta class . so after writing the code using this doc , i have a problem because the name of the field changes but the -> * character <- stays there .

Code :

from django.utils.translation import gettext_lazy as _
class Meta:
    model = ...
    fields = ...
    widgets = ...

    labels = {
        'email': _('email (necessary)'),
        'username': _('name (necessary)'), # the result of this -> name(necessary)* 
    }

Template :

{% extends "blog/base.html" %}
{% load crispy_forms_tags %}
{% block content %}

<h1>USERS REGISTER PAGE IS FOUND!</h1>
<br>
<hr>

<div>
    <form method="POST">
        {% csrf_token %}
        <fieldset class="form-group">
            <legend class="border-bottom mb-4">Join Today</legend>
            {{ form|crispy }}
        </fieldset>
        <div class="form-group">
            <button type="submit" class="btn btn-outline-info">Sign Up</button>
        </div>
    </form>
    <div class="border-top pt-3">
        <small class="text-muted">
            Already Have An Account ? <a class="ml-2" href="{% url 'users-login' %}">Sign In</a>
        </small>
    </div>
</div>

{% endblock content %}

so , how can I remove this annoying * ?

like image 680
Diyako Avatar asked Apr 06 '20 10:04

Diyako


1 Answers

The root cause here was apparently the django-crispy-forms package being used for rendering the form.

Its documentation has a section on the "required" asterisks; the easiest, as linked, is to hide the asterisk field; you don't need to change the labels:

.asteriskField {
    display: none;
}
like image 152
AKX Avatar answered Oct 13 '22 02:10

AKX