Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update many to many use select2 multiple #731

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions sqladmin/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,11 @@ def pre_validate(self, form: Form) -> None:
if v not in pk_list: # pragma: no cover
raise ValidationError(self.gettext("Not a valid choice"))

def __call__(self, **kwargs):
klass = kwargs.get("class_", "")
kwargs["class_"] = f'{klass} select2-multiple'
return super().__call__(**kwargs)


class AjaxSelectField(fields.SelectFieldBase):
widget = sqladmin_widgets.AjaxSelect2Widget()
Expand Down
10 changes: 9 additions & 1 deletion sqladmin/statics/css/main.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
.table thead th {
text-transform: none;
}
}

.select2-multiple {
width: 100% !important;
}

.select2-container--default .select2-selection--multiple .select2-selection__rendered li {
text-wrap: wrap;
}
5 changes: 5 additions & 0 deletions sqladmin/statics/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,3 +150,8 @@ $(':input[data-role="select2-tags"]').each(function () {
$(this).append(option).trigger('change');
}
});

// Select2 multiple
$(document).ready(function() {
$('.select2-multiple').select2();
});
Loading