Skip to content

Conversation

smallsam
Copy link

@smallsam smallsam commented Apr 4, 2025

In PR: https://github.com/jrief/django-formset/pull/94/files

the generation of client error messages broke and no longer reflects the behaviour of django form fields where the Field error_messages dict overrides those set on validators.

In particular the error code "invalid" was impacted, this fix should restore correct behaviour of the client side errors.

The testapp customer form, has a phone number field, this should fix the e2e field test for that field (which I believe is broken right now).

@jrief
Copy link
Owner

jrief commented Apr 4, 2025

Could you please describe how to reproduce this error.
You don't refer to any issue.

@smallsam
Copy link
Author

smallsam commented Apr 9, 2025

Sure. If you run the testapp in the django-formset repo.

If you visit: /default/customer

If you fill out "something" in the Phone Number field you will see "Enter a valid value" as the client side error.

image

This field is defined as below in django-formset/testapp/forms/customer.py

phone_number = fields.RegexField(
        r'^\+?[ 0-9.\-]{4,25}$',
        label="Phone Number",
        error_messages={'invalid': "Phone number have 4-25 digits and may start with '+'."},
        required=False,
    )

This PR fixes the behaviour and instead displays the error_message defined in the widget.

We would normally expect the "invalid" error_message to override the RegexValidator message. It appears the earlier PR (#94) added the if statement in the wrong place.

This PR fixes the expected override behaviour where error_messages defined in the widget override those raised by any validators. This was the original behaviour of django-formset in earlier releases.

@jrief
Copy link
Owner

jrief commented May 8, 2025

This has been fixed in upcoming version 2.0. If you want to try it out, please checkout the branch https://github.com/jrief/django-formset/tree/ModelAdmin-support

Thanks for reporting.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants