Add basic clientside validation for polls

This commit is contained in:
shpuld 2019-06-18 17:42:31 +03:00
parent e817b5b5a4
commit f243739954
4 changed files with 20 additions and 3 deletions

View File

@ -1,4 +1,5 @@
import * as DateUtils from 'src/services/date_utils/date_utils.js'
import { uniq } from 'lodash'
export default {
name: 'PollForm',
@ -105,8 +106,13 @@ export default {
this.expiryAmount
)
const options = uniq(this.options.filter(option => option !== ''))
if (options.length < 2) {
this.$emit('update-poll', { error: this.$t('polls.not_enough_options') })
return
}
this.$emit('update-poll', {
options: this.options,
options,
multiple: this.pollType === 'multiple',
expiresIn
})

View File

@ -193,6 +193,11 @@ const PostStatusForm = {
},
hideScopeNotice () {
return this.$store.state.config.hideScopeNotice
},
pollContentError () {
return this.pollFormVisible &&
this.newStatus.poll &&
this.newStatus.poll.error
}
},
methods: {
@ -261,6 +266,10 @@ const PostStatusForm = {
}
const poll = this.pollFormVisible ? this.newStatus.poll : {}
if (this.pollContentError) {
this.error = this.pollContentError
return
}
this.posting = true
statusPoster.postStatus({

View File

@ -102,7 +102,8 @@
"multiple_choices": "Multiple choices",
"expiry": "Poll age",
"expires_in": "Ends in {0}",
"expired": "Poll ended {0} ago"
"expired": "Poll ended {0} ago",
"not_enough_options": "Too few unique options in poll"
},
"interactions": {
"favs_repeats": "Repeats and Favorites",

View File

@ -66,7 +66,8 @@
"multiple_choices": "Monivalinta",
"expiry": "Äänestyksen kesto",
"expires_in": "Päättyy {0} päästä",
"expired": "Päättyi {0} sitten"
"expired": "Päättyi {0} sitten",
"not_enough_option": "Liian vähän uniikkeja vaihtoehtoja äänestyksessä"
},
"interactions": {
"favs_repeats": "Toistot ja tykkäykset",