[UPDT] HORILLA WIDGET: Condition for required field
This commit is contained in:
@@ -14,7 +14,7 @@ class HorillaForm(forms.Form):
|
||||
if isinstance(field_instance, HorillaMultiSelectField):
|
||||
self.errors.pop(field_name, None)
|
||||
if len(self.data.getlist(field_name)) < 1:
|
||||
raise forms.ValidationError({field_name: "Thif field is required"})
|
||||
raise forms.ValidationError({field_name: "This field is required"})
|
||||
cleaned_data = super().clean()
|
||||
employee_data = self.fields[field_name].queryset.filter(
|
||||
id__in=self.data.getlist(field_name)
|
||||
|
||||
@@ -138,7 +138,7 @@
|
||||
}
|
||||
</style>
|
||||
<div id="slectContainer{{self.attrs.id}}">
|
||||
<select name="{{field_name}}" id="{{self.attrs.id}}" class="w-100" multiple>
|
||||
<select name="{{field_name}}" id="{{self.attrs.id}}" {% if required %}required{% endif %} class="w-100" multiple>
|
||||
{% for instance in queryset %}
|
||||
<option value="{{instance.id}}">{{instance}}</option>
|
||||
{% endfor %}
|
||||
|
||||
@@ -19,9 +19,11 @@ class HorillaMultiSelectWidget(forms.Widget):
|
||||
filter_instance_contex_name=None,
|
||||
filter_template_path=None,
|
||||
instance=None,
|
||||
required=False,
|
||||
**kwargs
|
||||
) -> None:
|
||||
self.filter_route_name = filter_route_name
|
||||
self.required = required
|
||||
self.filter_class = filter_class
|
||||
self.filter_instance_contex_name = filter_instance_contex_name
|
||||
self.filter_template_path = filter_template_path
|
||||
@@ -42,6 +44,7 @@ class HorillaMultiSelectWidget(forms.Widget):
|
||||
context["self"] = self
|
||||
context["filter_template_path"] = self.filter_template_path
|
||||
context["filter_route_name"] = self.filter_route_name
|
||||
context["required"] = self.required
|
||||
self.attrs["id"] = ("id_" + name ) if self.attrs.get('id') is None else self.attrs.get("id")
|
||||
context[self.filter_instance_contex_name] = self.filter_class
|
||||
return context
|
||||
|
||||
Reference in New Issue
Block a user