Add input length validation for team names

This commit is contained in:
kolaente 2020-04-26 18:32:34 +02:00
parent f4847be320
commit d6642550bd
No known key found for this signature in database
GPG key ID: F40E70337AB24C9B
2 changed files with 30 additions and 3 deletions

View file

@ -15,6 +15,9 @@
<input v-focus :class="{ 'disabled': teamMemberService.loading}" :disabled="teamMemberService.loading" class="input" type="text" id="teamtext" placeholder="The team text is here..." v-model="team.name"> <input v-focus :class="{ 'disabled': teamMemberService.loading}" :disabled="teamMemberService.loading" class="input" type="text" id="teamtext" placeholder="The team text is here..." v-model="team.name">
</div> </div>
</div> </div>
<p class="help is-danger" v-if="showError && team.name.length <= 5">
Please specify at least five characters.
</p>
<div class="field"> <div class="field">
<label class="label" for="teamdescription">Description</label> <label class="label" for="teamdescription">Description</label>
<div class="control"> <div class="control">
@ -156,6 +159,8 @@
showUserDeleteModal: false, showUserDeleteModal: false,
user: auth.user, user: auth.user,
userIsAdmin: false, userIsAdmin: false,
showError: false,
} }
}, },
beforeMount() { beforeMount() {
@ -193,6 +198,12 @@
}) })
}, },
submit() { submit() {
if (this.team.name.length <= 4) {
this.showError = true
return
}
this.showError = false
this.teamService.update(this.team) this.teamService.update(this.team)
.then(response => { .then(response => {
this.team = response this.team = response

View file

@ -8,7 +8,12 @@
<form @submit.prevent="newTeam" @keyup.esc="back()"> <form @submit.prevent="newTeam" @keyup.esc="back()">
<div class="field is-grouped"> <div class="field is-grouped">
<p class="control is-expanded" v-bind:class="{ 'is-loading': teamService.loading}"> <p class="control is-expanded" v-bind:class="{ 'is-loading': teamService.loading}">
<input v-focus class="input" v-bind:class="{ 'disabled': teamService.loading}" v-model="team.name" type="text" placeholder="The team's name goes here..."> <input
v-focus
class="input"
:class="{ 'disabled': teamService.loading}" v-model="team.name"
type="text"
placeholder="The team's name goes here..."/>
</p> </p>
<p class="control"> <p class="control">
<button type="submit" class="button is-success noshadow"> <button type="submit" class="button is-success noshadow">
@ -19,6 +24,9 @@
</button> </button>
</p> </p>
</div> </div>
<p class="help is-danger" v-if="showError && team.name.length <= 5">
Please specify at least five characters.
</p>
</form> </form>
</div> </div>
</template> </template>
@ -35,6 +43,7 @@
return { return {
teamService: TeamService, teamService: TeamService,
team: TeamModel, team: TeamModel,
showError: false,
} }
}, },
beforeMount() { beforeMount() {
@ -50,9 +59,16 @@
}, },
methods: { methods: {
newTeam() { newTeam() {
if (this.team.name.length <= 4) {
this.showError = true
return
}
this.showError = false
this.teamService.create(this.team) this.teamService.create(this.team)
.then(response => { .then(response => {
router.push({name:'editTeam', params:{id: response.id}}) router.push({name: 'editTeam', params: {id: response.id}})
this.success({message: 'The team was successfully created.'}, this) this.success({message: 'The team was successfully created.'}, this)
}) })
.catch(e => { .catch(e => {