Форум сайта python.su
Здравствуйте!
Автокомплит работает только для тех форм которые я проинитил в представлении. Когда я с помощью jquery добваляю новую форму получаю по функционалу обычный charfield (все классы необходимые для автокомплита ему присваиваются).
Код:
#Form
class RegionLookup(ModelLookup): model = Region search_fields = ('name_ru__icontains', 'name_en__icontains') registry.register(RegionLookup) class ProfileSettingsIncRegionForm(forms.Form): include = AutoCompleteSelectField(required=False, label='', lookup_class=RegionLookup, widget=AutoCompleteSelectWidget(lookup_class=RegionLookup, attrs={'class': 'text small long include_region', 'placeholder': _('Choose region')})) # include = forms.IntegerField(required=False, widget=forms.HiddenInput(attrs={'class': 'chosen_region'}), label='') class Meta: model = ProfileSettingsRegion exclude = ('profile', 'name', 'exclude')
{% load selectable_tags %} {{ region_include_form_set.media }} {{ region_exclude_form_set.media }} {% block extrahead %}
<script type="text/javascript"> $(document).ready(function() { $('.include_row').formset({ prefix: '{{ region_include_form_set.prefix }}', added: function(row){ bindSelectables($(row)); $('.delete-row').text(''); }, removed: function(row){ if (!$('.include_row').is(':visible')) { $('.include_row').next('.add-row').trigger('click'); }} }); $('.include input[type=text]').djselectable(); $('.add-row').text(''); $('.delete-row').text(''); }); </script>
{% endblock %} <table style="width: 100%;"> <tr> <td style="vertical-align: top;width: 275px"> <div class="title include">{% trans "Please select the region for work" %}:</div> </td> <td style="vertical-align: top"> {% for form in region_include_form_set.forms %} <div class="include_row"> <div class="col" style="width: 55%"> {{ form.include }} {% if form.include.errors %} <div class="error">{{ form.include.errors }}</div>{% endif %} <div style="display: none;">{{ form.id }} {% if region_include_form_set.can_delete %}{{ form.DELETE }}{% endif %}</div> </div> </div> {% endfor %} </td> </tr> </table> {{ region_include_form_set.management_form }}
this.each(function() { var instance = $.data( this, fullName ); if ( instance ) { instance.option( options || {} )._init(); } else { $.data( this, fullName, new object( options, this ) ); } });
Отредактировано StimuL (Окт. 31, 2013 11:55:56)
Офлайн
Решил проблему так. Не красиво и не хорошо, но работает.
if ( instance ) { $.data( this, fullName, new object( options, this ) ); // instance.option( options || {} )._init(); } else { $.data( this, fullName, new object( options, this ) ); }
Офлайн