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

fix: required roles on user form not showing error msg #1772

Merged
merged 1 commit into from
Jan 6, 2022
Merged
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
4 changes: 2 additions & 2 deletions flask_appbuilder/fieldwidgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ class Select2Widget(widgets.Select):
def __init__(self, extra_classes=None, style=None):
self.extra_classes = extra_classes
self.style = style or u"width:250px"
return super(Select2Widget, self).__init__()
super(Select2Widget, self).__init__()

def __call__(self, field, **kwargs):
kwargs["class"] = u"my_select2 form-control"
Expand All @@ -163,7 +163,7 @@ class Select2ManyWidget(widgets.Select):
def __init__(self, extra_classes=None, style=None):
self.extra_classes = extra_classes
self.style = style or u"width:250px"
return super(Select2ManyWidget, self).__init__()
super(Select2ManyWidget, self).__init__()

def __call__(self, field, **kwargs):
kwargs["class"] = u"my_select2 form-control"
Expand Down
13 changes: 13 additions & 0 deletions flask_appbuilder/security/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,19 @@
from ..validators import PasswordComplexityValidator


class SelectDataRequired(DataRequired):
"""
Select required flag on the input field will not work well on Chrome
Console error:
An invalid form control with name='roles' is not focusable.

This makes a simple override to the DataRequired to be used specifically with
select fields
"""

field_flags = ()


class LoginForm_oid(DynamicForm):
openid = StringField(lazy_gettext("OpenID"), validators=[DataRequired()])
username = StringField(lazy_gettext("User Name"))
Expand Down
3 changes: 2 additions & 1 deletion flask_appbuilder/security/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
LoginForm_db,
LoginForm_oid,
ResetPasswordForm,
SelectDataRequired,
UserInfoEdit,
)
from .._compat import as_unicode
Expand Down Expand Up @@ -328,7 +329,7 @@ class UserDBModelView(UserModelView):
"conf_password",
]

validators_columns = {"roles": [validators.DataRequired()]}
validators_columns = {"roles": [SelectDataRequired()]}

@expose("/show/<pk>", methods=["GET"])
@has_access
Expand Down