Migrating from dal_select2 to dal_alight¶
This guide helps you migrate an existing dal_select2 project to
dal_alight. It’s not a requirement, but it’s supposed to be doable.
Why migrate¶
dal_select2 depends on jQuery, which puts the developer in charge of the
JavaScript object lifecycle. dal_alight uses native Web Components with no
external library dependency — no jQuery required.
Class name mapping¶
Replace Select2 with its Alight counterpart in your views, widgets, and
form fields.
|
|
|---|---|
|
|
|---|---|
Behavioural differences¶
Response format: Select2 views return JSON; alight views return HTML fragments. Override
get_result_label()instead ofget_result_label+get_selected_result_label.Create: the POST response returns an HTML label fragment, not
{"id": …, "text": …}JSON.Forwarding: the
forwardwidget argument anddal.forwardhelpers work identically.Admin registration:
ModelAdmin.formassignment works identically.Static files: replace
dal_select2media withdal_alightmedia; jQuery is no longer loaded by the widget.
Changes in 5.1¶
Since 5.1.0 (see CHANGELOG):
Widget
attrsapply to the visible search<input>, not a hidden<select>.ListAlightnow requires aurl; client-side local filtering of staticchoiceswas removed. UseListAlightwithAlightListView, or a plain<select>for tiny static lists.The
changeevent fires on<autocomplete-select>, not a<select>.AlightandAlightMultiplewere removed; use the widget mapping table above (Select2→ListAlight;Select2Multiple→ModelAlightMultipleorTagAlight).