Batching AjaxSelectFieldWidget

I am using this widget on a field with a named vocabulary. Unfortunately, the vocabulary has 20k+ terms in it and the widget appears to want to load them all at once. Surely there is a way to batch this - I know that the vocabulary itself supports it and if I call @@getVocabulary with batch={"page":1,"size":10} it works as expected. But I don't see any documentation on how to get the widget to make it do this. I have been looking through but haven't seen any sufficient clues.

1 Like

try plone.formwidget.autocomplete.widget.AutocompleteSelectionWidget, there you can provide a IQuerySource where you can have search method, which can filter the results.

I thought that widget was antiquated in Plone 5? I haven't seen anything that uses it in Plone 5 core.

Both SelectFieldWidget/AjaxSelectFieldWidget and RelationFieldWidget are based on select2 which allows for batching requests. For RelationFieldWidget this is what happens when you scroll down and it says "Loading more options" - it's making an ajax request to get the next page of the same query. It works really well.

I dug into this more and it looks like the relateditems pattern in mockup actually has some code to handle batching. It sets self.query to QueryHelper (mockup/js/utils.js) which, through several steps, assigns some instructions for selectAjax which is recognized by select2 (the plugin). The select2 pattern (in mockup) doesn't appear to have anything like this unless I am missing something? So the answer to my original question is probably that it is not currently supported. I suppose what I might be able to do is create a new pattern that is similar to the select2 pattern but incorporates QueryHelper's batching, and then subclass AjaxSelectFieldWidget to use this new pattern. It would be really nice if this were incorporated into the existing pattern and then you could just configure a batching option on the widget itself though.

As far as I remember, is this true for Select2 but not for the Mockup implementation :wink: