By default MultiWidget passes all attrs to each subwidget. To bypass this, you would have to subclass RangeWidget and provide separate attrs parameters for each of the from/to widgets.
If we use RangeFilter as blow source code, both input fields will be display ‘from’ in placeholder
1 2 3 4 5 6 |
lat = django_filters.RangeFilter( label='Laditude', widget=RangeWidget( attrs={'placeholder':'from'}, ) ) |
In order to set difference placeholder for each input field, we have to define a new RangeWidget. This is the source code
1 2 3 4 5 6 7 8 |
class MyRangeWidget(django_filters.widgets.RangeWidget): def __init__(self, from_attrs=None, to_attrs=None, attrs=None): super(MyRangeWidget, self).__init__(attrs) if from_attrs: self.widgets[0].attrs.update(from_attrs) if to_attrs: self.widgets[1].attrs.update(to_attrs) |
Below is source code that we use the RangeWidget:
1 2 3 4 5 6 7 8 |
# Filter by lat lat = django_filters.RangeFilter( label='Laditude', widget=MyRangeWidget( from_attrs={'placeholder':'from'}, to_attrs={'placeholder':'to'}, ) ) |
I am a Freelancer in programming specifically Python Scripting, Web scraping, and Web automation with 10+ years of experience.