I want to change in my form the color of the label_suffix.
I just want to set the '*' in red and leave the rest black. Is this possible or do i have to change something in my HTML?
username = forms.CharField(label="Username",label_suffix='*')
A red asterisk means that the field is "required" and you won't be able to submit the form without filling that field.
The is_valid() method is used to perform validation for each field of the form, it is defined in Django Form class. It returns True if data is valid and place all data into a cleaned_data attribute.
Django form fields define two types of functionality, a form field's HTML markup and its server-side validation facilities.
Get rid of this - label_suffix='*'
. We'll write some CSS to display a *
after the required fields.
First, in your form set an attribute called required_css_class
:
class MyForm(...):
required_css_class = 'required'
Django will set a class called required
in the HTML label and input for the field.
Now, put these lines your css file to display a red asterisk:
label.required::after {
content: ' *';
color: red;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With