I am thinking of a DRY method for using field labels for the placeholder attribute of my <input> HTML elements. I am using django-crispy-forms .
Now I have:
class FilterForm(Form): query = CharField(max_length=50, label='', required=False) def __init__(self, data=None, files=None, **kwargs): self.helper = FormHelper() self.helper.layout = Layout( Field('query', placeholder='Search ...'), ) super(FilterForm, self).__init__(data, files, **kwargs)
I would prefer, however, not to set the label and placeholder separately, since there will still be many fields for this, and this is pretty verbose.
What are your suggestions?
source share