2

I'm having a problem with changing my validation message from 'Please fill out this field' to 'Custom message blablabla': I tried to use something like this:

class NameForm(ModelForm):
    def __init__(self, *args, **kwargs):
          super(NameForm, self).__init__(*args, **kwargs)
          self.fields['name'].error_messages['required'] = 'Testing'

    class Meta:
        model = Player
        fields = ['name']
        widgets = {'name': forms.TextInput(
                     attrs={'id': 'player_name', 'required': True, 'placeholder': 'Player name...','value':'player1','title':'write here your name'}
            )
        }

but it doesn't seem to work. What am I missing? How can I customize my error message for a specific field when required is raised?

ePascoal
  • 2,362
  • 6
  • 26
  • 44
  • Possible duplicate: http://stackoverflow.com/questions/5384891/django-models-forms-replace-this-field-is-required-message – Jingo May 13 '15 at 13:23
  • @Jingo I saw that. I believe that issue can be similar but not duplicated. I am not quite sure if an error message is the same of validation message. 'Please fill out this field' is a error or validation message? if it is error message what am i doing wrong? if is a validation message how can i do this? Thanks by the way – ePascoal May 13 '15 at 13:33
  • Your example code **does work** for me (after I made a couple of minor changes). That means your problem is probably somewhere in your actual code, which you haven't shown us. – Alasdair May 13 '15 at 15:38
  • @Alasdair, thanks for your opinion. Please checkout my question again with my own code. – ePascoal May 13 '15 at 16:28
  • Your updated example code still works for me in Django 1.7.X. What do your view and template look like? – Alasdair May 14 '15 at 12:09
  • That's a HTML5 validation check. See [this answer](http://stackoverflow.com/questions/33014889/how-to-remove-please-fill-out-this-field-pop-up-when-click-on-submit-form-in-a). And [this for custom example](http://stackoverflow.com/questions/10753881/changing-the-language-of-error-message-in-required-field-in-html5-contact-form). – Raul Dias Mar 08 '17 at 03:28

0 Answers0