Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7621479
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T04:12:23+00:00 2026-05-31T04:12:23+00:00

I am working on multilanguage form which is translated by i18n and I’ve occurred

  • 0

I am working on multilanguage form which is translated by i18n and I’ve occurred a problem.

When I use {{ form.as_p }} for generating forms and I provide invalid data to the form, the data provided earlier is not being cleaned from the form – and I want same behavior in my custom form which will have some fields translated.

This is my custom form:

<div class="">
{{ form.subject.errors }}
<input class="contact_form" id="id_subject"
type="text" name="subject"
onfocus="if(this.value=='{% trans "Title" %}') this.value=''"
value="{% trans "Title" %}"
maxlength="128" />
</div>

How I can modify its behavior so it wont clean the provided data after an error? And only fields which contained invalid dada sould get removed from the form.

I couldn’t find anything in the django docs for that issue.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T04:12:24+00:00Added an answer on May 31, 2026 at 4:12 am

    Sander’s answer is correct, but if possible, you should try to avoid manually rendering your form fields in the template. In this case, you can set a initial value when you define the form:

    from django.utils.translation import ugettext_lazy, ugettext as _
    
    class MyForm(forms.Form):
        subject = Forms.CharField(initial=_("Title"), max_length=128))
    

    You can then write some javascript to handle the onfocus event. Here’s an untested snippet, using the jQuery .focus() method.

    <script type="text/javascript">
    $(function() {
      $('#id_subject').focus(function() {
        if (this.value == '{{ form.subject.initial }}') {
          this.value = '';
        }
      });
    });
    </script>
    

    You could also try passing the onfocus as a widget attribute. As you are using translatable strings, this might be a bit complicated – I think you might have to set the widget in the form’s __init__ method.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working in a website, that run on C#, which is multilanguage and one
i'm working on a multilanguage application with php5 and gettext. Rightnow i would like
Working with python interactively, it's sometimes necessary to display a result which is some
I'm working on php, mysql on a project I'm planning to add a multilanguage
Working on an extension that use the new experimental devtools apis. How do you
I'm working on making a skeleton from which to build small to medium-sized sites
I am currently working on a project which supports multi-language. I have created a
I am working on a WPF application. I set up a multilanguage with xml
I'm working on a multilanguage project with Zend Framework (German and English) where I
hi i'm working on a multilanguage project and. and i'm having some problemsi with

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.