-
Notifications
You must be signed in to change notification settings - Fork 37
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Selectize filter-by bug #162
Comments
Note, I also found that testapp includes incomplete attr in select tag, while it does not happen in custom project so as an additional workaround I need to put: my_field = ModelChoiceField(
...,
widget=Selectize(filter_by=..., attrs={"incomplete":True})
) If I don't put the incomplete tag, queries that have relationship similar to # testapp/forms/state.py
class StateForm(forms.Form):
state = models.ModelChoiceField(
label="State",
queryset=State.objects.all(),
widget=Selectize(
search_lookup='name__icontains',
),
# initial=2,
)
county = models.ModelChoiceField(
label="County",
queryset=County.objects.all(),
widget=Selectize(
search_lookup=['name__icontains'],
filter_by={'state': 'state__id'},
),
# initial=70,
) Overall, I just feel like the package is not updated with what is running in testapp. I'll try to check this out when I have time. Just sharing my workaround for now |
Upon further investigation, it seems that it's not the DjangoSelectize-*.js causing the issue but the lack of incomplete attribute in the select tag causing the issue. Therefore, the only needed workaround is to add SuggestionIn class IncompleteSelectMixin:
def build_attrs(self, base_attrs, extra_attrs):
attrs = super().build_attrs(base_attrs, extra_attrs)
if isinstance(self.choices, SimpleModelChoiceIterator):
if self.choices.queryset.count() > self.max_prefetch_choices:
attrs['incomplete'] = True
if self.filter_by:
attrs['filter-by'] = ','.join(self.filter_by.keys())
attrs['incomplete'] = True #intrdouce this if filter_by is also present in html attrs
return attrs Logic: Filter-by is technically always incomplete due to the filtering mechanism? |
I really like your deep investigation into problems. Would be nice if all other users of my libraries would dig that deep using their debugger. What you describe is weird indeed. However, when importing the right Please also try the monolithic build. There no asynchronous loading takes place. |
…-formset.js from testapp jrief#162
…-formset.js from testapp jrief#162
Regarding this, I should note that my conclusion for this issue is not particularly the js files but it's really related to the filtering functionality as referenced in my comment above: #162 (comment) I found that if the filtering field does not exceed the Please see replication of this issue here: For this implementation, please note that I just randomly sampled 200 counties for initial queryset of counties field. Therefore, for models with objects not yet exceeding 250, filter by will not work Reproduction Steps
Working Solutionclass IncompleteSelectMixin:
def build_attrs(self, base_attrs, extra_attrs):
attrs = super().build_attrs(base_attrs, extra_attrs)
if isinstance(self.choices, SimpleModelChoiceIterator):
if self.choices.queryset.count() > self.max_prefetch_choices:
attrs['incomplete'] = True
if self.filter_by:
attrs['filter-by'] = ','.join(self.filter_by.keys())
attrs['incomplete'] = True #intrdouce this if filter_by is also present in html attrs
return attrs |
In addition to @codematsing's investigation, when I change the parent select, the request to the view is duplicated—it runs twice. |
Confirmed. It is reproducible in https://django-formset.fly.dev/selectize/#filtering-select-options |
TL;DR:
Skip this (already identified as not the root cause)
Hi, Finally figured out the issue as to why Selectize filter-by functionality does not work in custom projects integrating django-formset library.
Note that this issue could not be replicated in the testapp for the investigation stated below.
I hope my explanation is clear. Please feel free to message me if it doesn't make sense
Issue:
How I discovered the issue:
DjangoSelectize-VSQ5POIH.js
is being imported in testapp, event thoughworkdir/static/formset/js/django-formset.js
importsDjangoSelectize-6XCBY3D6.js
formset/static/formset/js/django-formset.js
Conclusion and Summary:
formset/static/formset/js/django-formset.js
which importsDjangoSelectize-VSQ5POIH.js
(successfully triggers fetch request)workdir/static/formset/js/django-formset.js
which importsDjangoSelectize-6XCBY3D6.js
(unsuccessful tigger fetch request)My Workaround:
venv/lib/site-packages/.../formset/static/js/django-formset.js
to importDjangoSelectize-VSQ5POIH.js
Caveats:
DjangoSelectize-VSQ5POIH.js
andDjangoSelectize-6XCBY3D6.js
DjangoSelectize-*.js
file so I assume that rather than these files work simultaneously, these are mutually exclusive / differ in versionsThe text was updated successfully, but these errors were encountered: