Opened 3 weeks ago

Last modified 3 weeks ago

#35482 new Bug

Email and URL form input widgets should always have dir="ltr"

Reported by: Omid Shojaee Owned by: nobody
Component: Forms Version: 5.0
Severity: Normal Keywords: LTR, RTL, Admin, accessibility
Cc: Tom Carrick, Thibaud Colas, Sarah Abderemane, Claude Paroz Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: yes

Description

Regardless of the site's language, Username, Email and Password fields should be explicitly set to LTR direction in the Admin site. This is applicable to all RTL languages (Farsi, Arabic, Hebrew, etc).

Currently the solution is to override three forms (UserCreationForm, UserChangeForm and AdminPasswordChangeForm) as well as one HTML template (login.html of django.contrib.auth.admin) to achieve this.

Attachments (2)

test_login_button_centered--login--rtl.png (10.6 KB ) - added by Sarah Boyce 3 weeks ago.
test_first_field_focus--focus-single-widget--rtl.png (50.3 KB ) - added by Sarah Boyce 3 weeks ago.

Download all attachments as: .zip

Change History (14)

comment:1 by Sarah Boyce, 3 weeks ago

I believe what you're saying is that when a form labels are inline, the labels shouldn't be to the right of the inputs and should be to the left of them.
Below is what we have currently with the labels rendering to the right of the inputs.


When the labels are above the inputs, the current RTL formatting is correct


If I have understood correctly, then this should be fixed as part of #34643 which is to change the field labels to always be above the input (though we could accept a patch to fix the css in this case as that's quite a large change).

I'm not a RTL user myself, Omid Shojaee can you confirm whether my understanding is correct? I'm assuming you are a RTL user 🙂

Last edited 3 weeks ago by Sarah Boyce (previous) (diff)

comment:2 by Sarah Boyce, 3 weeks ago

Cc: Tom Carrick Thibaud Colas Sarah Abderemane added
Keywords: accessibility added

comment:3 by Omid Shojaee, 3 weeks ago

No Sarah, I'm talking about the textbox itself. The cursor inside the textbox must be set to Left-to-Right for Username, Email and Password fields.
The labels are actually displaying correctly.

Last edited 3 weeks ago by Omid Shojaee (previous) (diff)

comment:4 by Omid Shojaee, 3 weeks ago

I need to add that in an RTL site, all textbox and textfield elements should be RTL as well. However, for those specific fields, the direction of the cursor should be LTR. This is simply because only English characters are used there. I can't have Farsi password or use Farsi characters in my email address.

in reply to:  4 comment:5 by Sarah Boyce, 3 weeks ago

Cc: Claude Paroz added
Component: UncategorizedForms
Summary: Username, Email and Password fields should be explicitly set to LTREmail and URL form input widgets should always have dir="ltr"
Triage Stage: UnreviewedAccepted
Type: Cleanup/optimizationBug

Replying to Omid Shojaee:

This is simply because only English characters are used there.

This is not entirely true, usernames and passwords can use unicode characters.

I believe emails only accept ascii characters though and therefore now understand that this will need to be LTR, I think we need the same for the URL field.
Thank you for the report, accepting 👍

comment:6 by Omid Shojaee, 3 weeks ago

From RFCs point of view, yes it is possible to use unicode characters in username and password.

So I'd like to suggest an edit:

The ultimate solution would be to add an optional attribute, called "dir" or "direction" to CharField, TextField, EmailField, URLField, UUIDField, All Integer fields, FloatField and DecimanlField (numbers are always LTR), GenericIPAddressField, FileField and ImageField (operating system paths are always LTR) and leave it to the developers to decide the direction on the field level.

comment:7 by Sarah Boyce, 3 weeks ago

You can do this already by setting dir in the widget attrs

    example_text = forms.CharField(widget=forms.TextInput(attrs={"dir": "ltr"}))

If you don't think we should update any defaults for RTL to be LTR and the developers should update on case by case, then I can close this as wontfix?

comment:8 by Omid Shojaee, 3 weeks ago

I'm aware of that workaround and it involves some extra coding. Furthermore, it doesn't work everywhere (one example is the login.html template of django.contrib.auth.admin).

My suggestion helps developers to target one specific field easily, on the model level, based on their requirements.

EDIT:

I'm completely wrong. Please proceed with "Email and URL form input widgets should always have dir="ltr"

Last edited 3 weeks ago by Omid Shojaee (previous) (diff)

comment:9 by Omid Shojaee, 3 weeks ago

I'm completely wrong. Please proceed with "Email and URL form input widgets should always have dir="ltr"

in reply to:  6 comment:10 by Sarah Boyce, 3 weeks ago

Replying to Omid Shojaee:

...UUIDField, All Integer fields, FloatField and DecimanlField (numbers are always LTR), GenericIPAddressField, FileField and ImageField (operating system paths are always LTR)

Perhaps these should be updated as well? (alongside EmailField and URLField)

Last edited 3 weeks ago by Sarah Boyce (previous) (diff)

comment:11 by Claude Paroz, 3 weeks ago

In any case, having a forum thread with opinions from other RTL-language developers would be welcome!

comment:12 by Omid Shojaee, 3 weeks ago

The perfect implementation would be:

  • Email widget: Always LTR
  • Always LTR for the following fields:
  1. BigIntegerField
  2. BinaryField
  3. DecimalField
  4. EmailField
  5. FileField
  6. FilePathField
  7. FloatField
  8. GenericIPAddressField
  9. ImageField
  10. IntegerField
  11. JSONField (never worked with it. don't know how it is displayed in the admin site)
  12. PositiveBigIntegerField
  13. PositiveIntegerField
  14. PositiveSmallIntegerField
  15. SmallIntegerField
  16. URLField
  17. UUIDField
  • And, optional "dir" argument for CharField and TextField in case someone needs it.

I believe the above will totally eliminate the need to override model forms just to add proper direction.

Last edited 3 weeks ago by Omid Shojaee (previous) (diff)
Note: See TracTickets for help on using tickets.
Back to Top