4

I'm running into an issue of only being able to have either a custom error message OR placeholder text. As soon as the custom error message is added into the ModelForm the placeholder text is no longer showing— order does not effect result. Thanks in advance for any help and suggestions!

class LetterForm(ModelForm):
    name = forms.CharField()
    class Meta:
       model = Letter
       exclude = ('date_submitted', 'read', 'approved', 'post', 'date_post', 'url', 'tags',)
       widgets = {
        'youtube': forms.TextInput(attrs={'placeholder': 'youtube'}),
        'name': forms.TextInput(attrs={'placeholder': 'name'}),
        'location': forms.TextInput(attrs={'placeholder': 'location'}),
        'email': forms.TextInput(attrs={'placeholder': 'email'}),
    }
    name = forms.CharField(error_messages={'required': 'Don\'t want to share your real name?'
                                                       ' Just enter Anonymous.'})
2
  • Just a shot: would this work? name = forms.CharField(error_messages={'required': 'Don\'t want to share your real name?, Just enter Anonymous.'}, widget=forms.TextInput(attrs={'placeholder': 'name'})
    – karthikr
    Apr 15, 2013 at 18:42
  • @karthikr yup! I actually just figured it out prior to your post. Thanks for the heads up though. Respect.
    – alxmrph
    Apr 15, 2013 at 18:44

1 Answer 1

3

Figured it out. I'll just leave this here for anyone that might interested

name = forms.CharField(error_messages={'required': 'message'},
                       widget=forms.TextInput(attrs={'placeholder': 'Name'}))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.