Skip to content

Commit 011b747

Browse files
committed
Fix input for groups validation in new user form
The hidden input used for form validation was not actually hidden, so it was shown as a strange input field (it was either empty or it showed the string representation of the groups array). Although just hiding it will still keep the validation working when the input is hidden the browser may not show any validation error in the UI, so it would not be possible to create the user for "unknown" reasons. Moreover, the validation API does not provide a way to bind the message to a different element, and even if the message could be shown using a Vue tooltip it would not follow the same style as the other native messages in the rest of the elements. The Multiselect component internally uses an input element, so now that one is used for the validation instead of an additional "hidden" input. That internal element is always empty (the selected groups are shown in an auxiliary div), so the "required" attribute needs to be explicitly set and removed on the input based on the currently selected groups. Signed-off-by: Daniel Calviño Sánchez <danxuliu@gmail.com>
1 parent 03b424a commit 011b747

5 files changed

Lines changed: 43 additions & 16 deletions

File tree

apps/settings/js/vue-settings-apps-users-management.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apps/settings/js/vue-settings-apps-users-management.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apps/settings/js/vue-settings-users.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apps/settings/js/vue-settings-users.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apps/settings/src/components/UserList.vue

Lines changed: 36 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -75,15 +75,8 @@
7575
name="email"
7676
type="email">
7777
<div class="groups modal__item">
78-
<!-- hidden input trick for vanilla html5 form validation -->
79-
<input v-if="!settings.isAdmin"
80-
id="newgroups"
81-
:class="{'icon-loading-small': loading.groups}"
82-
:required="!settings.isAdmin"
83-
:value="newUser.groups"
84-
tabindex="-1"
85-
type="text">
86-
<Multiselect v-model="newUser.groups"
78+
<Multiselect ref="newusergroups"
79+
v-model="newUser.groups"
8780
:close-on-select="false"
8881
:disabled="loading.groups||loading.all"
8982
:multiple="true"
@@ -401,6 +394,20 @@ export default {
401394
this.$refs.infiniteLoading.stateChanger.loaded()
402395
}
403396
},
397+
'newUser.groups'() {
398+
this.requireGroupsIfNeeded()
399+
},
400+
'showConfig.showNewUserForm'(val) {
401+
if (!val) {
402+
return
403+
}
404+
405+
// Wait until next tick, as otherwise the element and its reference
406+
// will not be initialized.
407+
this.$nextTick(() => {
408+
this.requireGroupsIfNeeded()
409+
})
410+
},
404411
},
405412
406413
mounted() {
@@ -546,6 +553,26 @@ export default {
546553
this.newUser.groups = []
547554
},
548555
556+
/**
557+
* Set the group input as "required" if needed.
558+
*
559+
* Sub admins can create users only in the groups they manage, so at
560+
* least one group needs to be selected for the form to be valid.
561+
*
562+
* The selected groups are shown in an auxiliary div, but not in the
563+
* input itself. Therefore, the "required" attribute needs to be set
564+
* when there are no selected groups, but it needs to be removed
565+
* otherwise, as the input will be empty and fail validation even if
566+
* some group is already selected.
567+
*/
568+
requireGroupsIfNeeded() {
569+
if (this.settings.isAdmin || !this.$refs.newusergroups) {
570+
return
571+
}
572+
573+
this.$refs.newusergroups.$refs.VueMultiselect.$refs.search.required = !this.newUser.groups.length
574+
},
575+
549576
/**
550577
* Create a new group
551578
*

0 commit comments

Comments
 (0)