Hi Jacob,
I’ve been investigating this issue on my end, but I’m currently blocked on identifying where the solution should be applied.
Setup
states = forms.ModelMultipleChoice(
initial=[2, 47],
widget=SelectizeMultiple
)
counties = forms.ModelMultipleChoice(
initial=[...], # 10 items
widget=DualSelector(filter_by={"state": "state_id"})
)
Expectation
- The
DualSelector should pre-populate all 10 initial values.
Actual Behavior
- The
DualSelector only captures a subset of the initial values.
Findings and observations
- IF
DualSelector does NOT use the filter_by parameter, the expected behavior occurs.
- Issue only occurs when filter_by is set, and basis of filter also has initial values
- When a form widget inherits from
IncompleteSelectMixin, the queryset is sliced to [:max_prefetch_choices]; consequently,
- The
views.IncompleteSelectResponseMixin is responsible for dynamically updating the available options for a select field but will always display max_length=max_prefetch_choices.
- From browser dev tools, I observed that during the initial load, a network request is triggered:
http://localhost:8000/bootstrap/states?offset=0&filter-states=2&filter-states=47&field=__default__.counties
In my opinion, an improvement should be done on views.IncompleteSelectResponseMixin to choices=qs[:max_prefetch] + <field's initial values>, atleast on initial load?
Replication
- See replication here
- Go to: http://localhost:8000/bootstrap/states
- Note: I made max_prefetch_choices=5 to simplify test case and capture the case that's happening even when max_prefetch_choices is significantly higher (i.e. 250/default)
- Expected: 5 AK, 5 VA preselected values on page load. Similar to below. Instead, this occurs when counties form field does not have a "filter_by" parameter
- Actual: Only values in AK are pre-selected.
Any guidance would be appreciated.
Hi Jacob,
I’ve been investigating this issue on my end, but I’m currently blocked on identifying where the solution should be applied.
Setup
Expectation
DualSelectorshould pre-populate all 10 initial values.Actual Behavior
DualSelectoronly captures a subset of the initial values.Findings and observations
DualSelectordoes NOT use thefilter_byparameter, the expected behavior occurs.IncompleteSelectMixin, the queryset is sliced to[:max_prefetch_choices]; consequently,views.IncompleteSelectResponseMixinis responsible for dynamically updating the available options for a select field but will always display max_length=max_prefetch_choices.In my opinion, an improvement should be done on
views.IncompleteSelectResponseMixintochoices=qs[:max_prefetch] + <field's initial values>, atleast on initial load?Replication
Any guidance would be appreciated.