#34735 closed Cleanup/optimization (invalid)

About form validation

Reported by: Anis Owned by: Anis
Component: Forms Version: 4.2
Severity: Normal Keywords: forms ValidationError
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Greeting i'm trying to customise the ValidationError message i got this "veuillez renseigner ce champ" as a toolip under the input field my web site is in other language and already setup in settings.py this is my forms.py

class OrganismForm(forms.ModelForm):

    class Meta:
        model = Organism
        fields = ['code', 'name', 'parent', 'region']
        exclude = []
        widgets = {
            'code': forms.TextInput(attrs={'class': 'form-control form-control-outline',
                                           'placeholder':'Placeholder' ,
                                           'data-listener-added_b000d9d8':'true'}),
            'name': forms.TextInput(attrs={'class': 'form-control form-control-outline',
                                           'placeholder':'Placeholder' ,
                                           'data-listener-added_b000d9d8':'true'}),
            'parent': forms.Select(attrs={'class': 'select select2-hidden-accessible',                
                }),
            'region': forms.Select(attrs={'class': 'select select2-hidden-accessible',                
                }),
        }
        localized_fields = None
        labels = {}
        help_texts = {}
        error_messages = {}

    def __init__(self, *args, **kwargs):
        return super(OrganismForm, self).__init__(*args, **kwargs)

    def is_valid(self):
        return super(OrganismForm, self).is_valid()

    def full_clean(self):
        return super(OrganismForm, self).full_clean()

    def clean_code(self):
        code = self.cleaned_data.get("code", None)
        return code

    def clean_name(self):
        name = self.cleaned_data.get("name", None)
        if not name:
            raise ValidationError('custom text message.')
        return name

    def clean_parent(self):
        parent = self.cleaned_data.get("parent", None)
        return parent

    def clean_region(self):
        region = self.cleaned_data.get("region", None)
        return region

    def clean(self):
        return super(OrganismForm, self).clean()

    def validate_unique(self):
        return super(OrganismForm, self).validate_unique()

    def save(self, commit=True):
        return super(OrganismForm, self).save(commit)

Change History (6)

comment:1 by Anis, 14 months ago

Cc: Anis added
Component: UncategorizedForms
Keywords: forms ValidationError added

comment:2 by Anis, 14 months ago

Cc: Anis removed
Owner: changed from nobody to Anis
Status: newassigned

comment:3 by Mariusz Felisiak, 14 months ago

Resolution: invalid
Status: assignedclosed

Please don't use Trac as a support channel. If you're having trouble understanding how Django works, see TicketClosingReasons/UseSupportChannels for ways to get help.

comment:4 by Anis, 14 months ago

Type: UncategorizedCleanup/optimization

comment:5 by Anis, 14 months ago

Resolution: invalid
Status: closednew

comment:6 by Mariusz Felisiak, 14 months ago

Resolution: invalid
Status: newclosed

Anis, please don't reopen closed tickets.

Note: See TracTickets for help on using tickets.
Back to Top