oTree Forum >

Overwrite Global Error Message

#1 by freddsch

Hey everyone, 

is there a way to overwrite the message displayed for a necessary field? In german it would be 'Bitte korrigieren Sie die Fehler', something like please correct the mistakes with a red sign on top. 

I would like it to say something else and it would be a lot of code to rewrite it for every entry.

Thanks!

#2 by AndreL

Tagging alone in a similar question, I want to know what is the Otree Lite equivalent of having the following custom snippet:

===========================================
    <style>
       .otree-form-errors {
            display: none;
        }
    </style>
     
     {{ if form.errors }}
        <div class="alert alert-danger" role="alert">
            <h6 class="alert-heading">{{ form.non_field_errors }}</h6>
        </div>
    {{ endif }}
    
    {{ formfields }}
    {{ next_button }}
 =============================================

... such that I can customize the appearance of the error using Boostrap arguments

#3 by Chris_oTree

If you want to customize the appearance of the error banner, I recommend using CSS on the .otree-form-errors element. Or select that element with JavaScript and customize its appearance, classes, etc.

#4 by gmdcastillo

It would be great to have {{ if form.errors }} in oTree Lite.

> If you want to customize the appearance of the error banner, I recommend using CSS on the .otree-form-errors element. Or select that element with JavaScript and customize its appearance, classes, etc.

But how do you know whether the form has been submitted and has been rejected server-side?

#5 by Chris_oTree

{{ if form.errors }} does work on oTree Lite.

#6 by Chris_oTree

I think the thing that is not supported in oTree Lite is form.non_field_errors, the rest of it should work.

#7 by gmdcastillo

Aaaah great! I thought your message above meant that {{ if form.errors }} does not work. All good then.

In the meantime I had done this which also does the trick:

<script>
    const errorDiv = document.querySelector('.otree-form-errors');

    if (errorDiv) {
        errorDiv.textContent = 'My new text'
    }
</script>

Write a reply

Set forum username