mirror of
https://github.com/Ocelot-Social-Community/Ocelot-Social.git
synced 2025-12-13 07:46:06 +00:00
disable submit button for invalid input
This commit is contained in:
parent
68543aa823
commit
0275971381
@ -221,6 +221,7 @@
|
|||||||
"reportContent": "Melden",
|
"reportContent": "Melden",
|
||||||
"validations": {
|
"validations": {
|
||||||
"email": "muss eine gültige E-Mail Adresse sein",
|
"email": "muss eine gültige E-Mail Adresse sein",
|
||||||
|
"url": "muss eine gültige URL sein",
|
||||||
"verification-code": "muss genau 6 Buchstaben lang sein"
|
"verification-code": "muss genau 6 Buchstaben lang sein"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
@ -222,6 +222,7 @@
|
|||||||
"reportContent": "Report",
|
"reportContent": "Report",
|
||||||
"validations": {
|
"validations": {
|
||||||
"email": "must be a valid email address",
|
"email": "must be a valid email address",
|
||||||
|
"url": "must be a valid URL",
|
||||||
"verification-code": "must be 6 characters long"
|
"verification-code": "must be 6 characters long"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
@ -110,11 +110,7 @@ describe('my-social-media.vue', () => {
|
|||||||
describe('currentUser does not have a social media account linked', () => {
|
describe('currentUser does not have a social media account linked', () => {
|
||||||
it('allows a user to add a social media link', () => {
|
it('allows a user to add a social media link', () => {
|
||||||
wrapper = Wrapper()
|
wrapper = Wrapper()
|
||||||
input = wrapper.find({ name: 'social-media' })
|
wrapper.find('form').trigger('submit')
|
||||||
input.element.value = socialMediaUrl
|
|
||||||
input.trigger('input')
|
|
||||||
submitBtn = wrapper.find('.ds-button')
|
|
||||||
submitBtn.trigger('click')
|
|
||||||
expect(mocks.$apollo.mutate).toHaveBeenCalledTimes(1)
|
expect(mocks.$apollo.mutate).toHaveBeenCalledTimes(1)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
@ -26,24 +26,34 @@
|
|||||||
</ds-list>
|
</ds-list>
|
||||||
</ds-space>
|
</ds-space>
|
||||||
<ds-space margin-top="base">
|
<ds-space margin-top="base">
|
||||||
<div>
|
<ds-form
|
||||||
<ds-input
|
v-model="formData"
|
||||||
v-model="value"
|
:schema="formSchema"
|
||||||
:placeholder="$t('settings.social-media.placeholder')"
|
@submit="handleAddSocialMedia"
|
||||||
name="social-media"
|
@input="handleInput"
|
||||||
:schema="{ type: 'url' }"
|
@input-valid="handleInputValid"
|
||||||
/>
|
>
|
||||||
</div>
|
<template>
|
||||||
<ds-space margin-top="base">
|
<ds-input
|
||||||
<div>
|
id="socialMediaLink"
|
||||||
<ds-button primary @click="handleAddSocialMedia">
|
name="social-media"
|
||||||
{{ $t('settings.social-media.submit') }}
|
model="socialMediaLink"
|
||||||
</ds-button>
|
type="text"
|
||||||
</div>
|
:placeholder="$t('settings.social-media.placeholder')"
|
||||||
</ds-space>
|
/>
|
||||||
|
<ds-space margin-top="base">
|
||||||
|
<div>
|
||||||
|
<ds-button primary :disabled="disabled">
|
||||||
|
{{ $t('settings.social-media.submit') }}
|
||||||
|
</ds-button>
|
||||||
|
</div>
|
||||||
|
</ds-space>
|
||||||
|
</template>
|
||||||
|
</ds-form>
|
||||||
</ds-space>
|
</ds-space>
|
||||||
</ds-card>
|
</ds-card>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import gql from 'graphql-tag'
|
import gql from 'graphql-tag'
|
||||||
import { mapGetters, mapMutations } from 'vuex'
|
import { mapGetters, mapMutations } from 'vuex'
|
||||||
@ -51,7 +61,16 @@ import { mapGetters, mapMutations } from 'vuex'
|
|||||||
export default {
|
export default {
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
value: '',
|
formData: {
|
||||||
|
socialMediaLink: '',
|
||||||
|
},
|
||||||
|
formSchema: {
|
||||||
|
socialMediaLink: {
|
||||||
|
type: 'url',
|
||||||
|
message: this.$t('common.validations.url'),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
disabled: true,
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
@ -73,20 +92,31 @@ export default {
|
|||||||
...mapMutations({
|
...mapMutations({
|
||||||
setCurrentUser: 'auth/SET_USER',
|
setCurrentUser: 'auth/SET_USER',
|
||||||
}),
|
}),
|
||||||
handleAddSocialMedia() {
|
async handleInput(data) {
|
||||||
|
this.disabled = true
|
||||||
|
},
|
||||||
|
async handleInputValid(data) {
|
||||||
|
if (data.socialMediaLink.length < 1) {
|
||||||
|
this.disabled = true
|
||||||
|
} else {
|
||||||
|
this.disabled = false
|
||||||
|
}
|
||||||
|
},
|
||||||
|
async handleAddSocialMedia() {
|
||||||
|
const mutation = gql`
|
||||||
|
mutation($url: String!) {
|
||||||
|
CreateSocialMedia(url: $url) {
|
||||||
|
id
|
||||||
|
url
|
||||||
|
}
|
||||||
|
}
|
||||||
|
`
|
||||||
|
const variables = { url: this.formData.socialMediaLink }
|
||||||
|
|
||||||
this.$apollo
|
this.$apollo
|
||||||
.mutate({
|
.mutate({
|
||||||
mutation: gql`
|
mutation,
|
||||||
mutation($url: String!) {
|
variables,
|
||||||
CreateSocialMedia(url: $url) {
|
|
||||||
id
|
|
||||||
url
|
|
||||||
}
|
|
||||||
}
|
|
||||||
`,
|
|
||||||
variables: {
|
|
||||||
url: this.value,
|
|
||||||
},
|
|
||||||
update: (store, { data }) => {
|
update: (store, { data }) => {
|
||||||
const socialMedia = [...this.currentUser.socialMedia, data.CreateSocialMedia]
|
const socialMedia = [...this.currentUser.socialMedia, data.CreateSocialMedia]
|
||||||
this.setCurrentUser({
|
this.setCurrentUser({
|
||||||
@ -97,7 +127,8 @@ export default {
|
|||||||
})
|
})
|
||||||
.then(() => {
|
.then(() => {
|
||||||
this.$toast.success(this.$t('settings.social-media.successAdd'))
|
this.$toast.success(this.$t('settings.social-media.successAdd'))
|
||||||
this.value = ''
|
this.formData.socialMediaLink = ''
|
||||||
|
this.disabled = true
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
this.$toast.error(error.message)
|
this.$toast.error(error.message)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user