Skip to content

Commit

Permalink
Fehler bei leeren Inputs (#856)
Browse files Browse the repository at this point in the history
* Detect empty inputs in ServerCard form

* Add required field to some forms
  • Loading branch information
ssrahn authored Dec 14, 2023
1 parent 6d9c108 commit 3dc521f
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 40 deletions.
63 changes: 30 additions & 33 deletions vueapp/components/Config/ConfigOption.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
:name="setting.name"
:checked="setting.value == true"
@change='setValue(true)'
:required="setting.required"
>
<translate>
Ja
Expand All @@ -26,6 +27,7 @@
:name="setting.name"
:checked="setting.value != true"
@change='setValue(false)'
:required="setting.required"
>
<translate>
Nein
Expand All @@ -44,7 +46,8 @@
:name="setting.name"
:placeholder="setting.placeholder"
v-model="setting.value"
@change="setValue(setting.value)">
@change="setValue(setting.value)"
:required="setting.required">
</label>

<label v-if="(setting.type == 'string' || setting.type == 'integer') && setting.options && !isI18N(setting)">
Expand All @@ -71,7 +74,8 @@
:name="setting.name"
:placeholder="setting.placeholder"
v-model="setting.value"
@change="setValue(setting.value)">
@change="setValue(setting.value)"
:required="setting.required">
</label>

<label v-if="setting.type == 'password'">
Expand All @@ -85,11 +89,12 @@
<div class="input-group files-search oc--admin-password">

<input :type="passwordVisible ? 'text' : 'password'"
@change="updateHiddenPassword"
@focusin="clearTextFieldIfHidden"
@focusout="fillTextFieldIfHidden"
@change="setValue(password)"
@focusin="passwordFocused=true"
@focusout="passwordFocused=false"
v-model="password"
:placeholder="setting.placeholder"
:required="setting.required"
>

<span class="input-group-append ">
Expand Down Expand Up @@ -132,16 +137,29 @@ export default {
data() {
return {
password: '*****',
passwordVisible: false
passwordInput: '', // Make password initially empty, so that an empty input can be detected
passwordVisible: false,
passwordFocused: false
}
},
mounted() {
if (!this.passwordVisible && this.setting.type == 'password'
&& this.setting.value)
{
this.password = '*****';
computed: {
password: {
get() {
if (!this.passwordVisible) {
if (this.passwordFocused && this.passwordInput == '*****') {
this.passwordInput = '';
}
else if (!this.passwordFocused && this.setting.value) {
this.passwordInput = '*****';
}
}
return this.passwordInput;
},
set(newValue) {
this.passwordInput = newValue;
}
}
},
Expand All @@ -157,31 +175,10 @@ export default {
this.password = this.setting.value;
this.passwordVisible = true;
} else {
if (this.setting.value) {
this.password = '*****';
}
this.passwordVisible = false;
}
},
updateHiddenPassword() {
this.setValue(this.password);
},
clearTextFieldIfHidden()
{
if (!this.passwordVisible && this.password == '*****') {
this.password = '';
}
},
fillTextFieldIfHidden()
{
if (!this.passwordVisible && this.password.length == 0) {
this.password = '*****';
}
},
isI18N(setting)
{
if (
Expand Down
7 changes: 6 additions & 1 deletion vueapp/components/Config/EditServer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
@close="close"
>
<template v-slot:dialogContent ref="editServer-dialog">
<form class="default" v-if="currentConfig">
<form class="default" v-if="currentConfig" ref="editServer-form">
<fieldset>
<legend>
{{ $gettext('Grundeinstellungen') }}
Expand Down Expand Up @@ -175,7 +175,12 @@ export default {
},
storeConfig() {
if (!this.$refs['editServer-form'].reportValidity()) {
return false;
}
this.disabled = true;
this.$store.dispatch('clearMessages');
this.currentConfig.checked = false;
Expand Down
6 changes: 5 additions & 1 deletion vueapp/components/Playlists/PlaylistAddNewCard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,14 @@
@keyup.enter="createPlaylist"
>
<template v-slot:dialogContent>
<form class="default">
<form class="default" ref="playlistAddNewCard-form">
<label>
<span class="required">Titel</span>
<input type="text"
maxlength="255"
:placeholder="$gettext('Titel der Wiedergabeliste')"
v-model="playlist.title"
required
>
</label>
</form>
Expand Down Expand Up @@ -50,6 +51,9 @@ export default {
methods: {
createPlaylist() {
if (!this.$refs['playlistAddNewCard-form'].reportValidity()) {
return false;
}
this.$store.dispatch('addPlaylist', this.playlist);
this.$emit('done');
}
Expand Down
9 changes: 6 additions & 3 deletions vueapp/components/Playlists/PlaylistEditCard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
@confirm="updatePlaylist"
>
<template v-slot:dialogContent>
<form class="default">
<form class="default" ref="playlistEditCard-form">
<label v-if="!isDefaultCoursePlaylist">
Name
<input type="text" v-model="eplaylist.title">
<span class="required">Titel</span>
<input type="text" v-model="eplaylist.title" required>
</label>

<!--
Expand Down Expand Up @@ -77,6 +77,9 @@ export default {
methods: {
updatePlaylist() {
if (!this.$refs['playlistEditCard-form'].reportValidity()) {
return false;
}
this.playlist.title = this.eplaylist.title;
this.playlist.visibility = this.eplaylist.visibility;
this.playlist.tags = JSON.parse(JSON.stringify((this.eplaylist.tags)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
</fieldset>
<footer>
<StudipButton
:disabled="selectedUser == null"
:disabled="selectedUser == null || selectedUserPerm == null"
icon="accept"
@click.prevent="addShareUser()"
>
Expand Down
5 changes: 4 additions & 1 deletion vueapp/components/Videos/Actions/VideoEdit.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
@confirm="accept"
>
<template v-slot:dialogContent>
<form class="default" style="max-width: 50em;" @submit="editVideo">
<form class="default" style="max-width: 50em;" @submit="editVideo" ref="videoEdit-form">
<fieldset>
<label>
<span class="required" v-translate>
Expand Down Expand Up @@ -151,6 +151,9 @@ export default {
methods: {
async accept() {
if (!this.$refs['videoEdit-form'].reportValidity()) {
return false;
}
// Handle visibility
this.event.cid = this.cid;
this.event.playlist_token = this.playlist?.token;
Expand Down

0 comments on commit 3dc521f

Please sign in to comment.