Skip to content

Commit

Permalink
fix #126 - add widget_options for each field
Browse files Browse the repository at this point in the history
  • Loading branch information
crucialfelix committed Nov 3, 2015
1 parent e42b9ce commit a1d2be2
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions ajax_select/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,16 +110,15 @@ class AutoCompleteSelectField(forms.fields.CharField):

def __init__(self, channel, *args, **kwargs):
self.channel = channel
widget = kwargs.get("widget", False)

if not widget or not isinstance(widget, AutoCompleteSelectWidget):
widget_kwargs = dict(
channel=channel,
help_text=kwargs.get('help_text', _(as_default_help)),
show_help_text=kwargs.pop('show_help_text', True),
plugin_options=kwargs.pop('plugin_options', {})
)
kwargs["widget"] = AutoCompleteSelectWidget(**widget_kwargs)

widget_kwargs = dict(
channel=channel,
help_text=kwargs.get('help_text', _(as_default_help)),
show_help_text=kwargs.pop('show_help_text', True),
plugin_options=kwargs.pop('plugin_options', {})
)
widget_kwargs.update(kwargs.pop('widget_options', {}))
kwargs["widget"] = AutoCompleteSelectWidget(**widget_kwargs)
super(AutoCompleteSelectField, self).__init__(max_length=255, *args, **kwargs)

def clean(self, value):
Expand Down Expand Up @@ -272,6 +271,7 @@ def __init__(self, channel, *args, **kwargs):
'show_help_text': show_help_text,
'plugin_options': kwargs.pop('plugin_options', {})
}
widget_kwargs.update(kwargs.pop('widget_options', {}))
kwargs['widget'] = AutoCompleteSelectMultipleWidget(**widget_kwargs)
kwargs['help_text'] = help_text

Expand Down Expand Up @@ -354,6 +354,7 @@ def __init__(self, channel, *args, **kwargs):
show_help_text=kwargs.pop('show_help_text', True),
plugin_options=kwargs.pop('plugin_options', {})
)
widget_kwargs.update(kwargs.pop('widget_options', {}))
if 'attrs' in kwargs:
widget_kwargs['attrs'] = kwargs.pop('attrs')
widget = AutoCompleteWidget(channel, **widget_kwargs)
Expand Down

0 comments on commit a1d2be2

Please sign in to comment.