Skip to content

Commit 03fe5f0

Browse files
authored
feat: ArrayWidget custom widget class parameter (#1432)
1 parent 08680fd commit 03fe5f0

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

src/unfold/contrib/forms/widgets.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,25 @@
3333
class ArrayWidget(MultiWidget):
3434
template_name = "unfold/forms/array.html"
3535

36-
def __init__(self, *args: Any, **kwargs: Any) -> None:
36+
def __init__(
37+
self,
38+
widget_class: Optional[type[Widget]] = None,
39+
*args: Any,
40+
**kwargs: Any,
41+
) -> None:
3742
if "choices" in kwargs:
3843
self.choices = kwargs["choices"]
3944

45+
if widget_class is not None:
46+
self.widget_class = widget_class
47+
4048
widgets = [self.get_widget_instance()]
4149
super().__init__(widgets)
4250

4351
def get_widget_instance(self) -> Any:
52+
if hasattr(self, "widget_class"):
53+
return self.widget_class()
54+
4455
if hasattr(self, "choices"):
4556
return UnfoldAdminSelectWidget(choices=self.choices)
4657

src/unfold/templates/unfold/widgets/text.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
<div class="max-w-2xl relative">
2+
<div class="max-w-2xl relative w-full">
33
{% if widget.prefix %}
44
<span class="absolute left-3 top-0 bottom-0 flex items-center justify-center">
55
{{ widget.prefix }}

0 commit comments

Comments
 (0)