-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: lexemes cannot be disabled as button is rendered outside of form #776
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
<template> | ||
<v-form ref="form" v-model="valid" @submit="confirmAction"> | ||
<v-form ref="form" v-model="valid" @submit="handleSubmit" id="formLexeme"> | ||
<v-card elevation="1" class="padding" outlined> | ||
<v-card-title>Lexeme</v-card-title> | ||
<v-card-text> | ||
|
@@ -8,7 +8,7 @@ | |
</v-card-text> | ||
<v-card-actions> | ||
<v-btn @click="showModal" color="red" v-if="isEnabled">Disable Lexeme</v-btn> | ||
<v-btn @click="enableFeature" v-else>Enable Lexeme</v-btn> | ||
<v-btn v-else type="submit">Enable Lexeme</v-btn> | ||
</v-card-actions> | ||
</v-card> | ||
<v-dialog v-model="dialog" width="500" v-if="dialog"> | ||
|
@@ -28,15 +28,16 @@ | |
<v-text-field | ||
:label="`Please type ${userConfirmationString} to confirm`" | ||
:rules="[rules.match]" | ||
></v-text-field> | ||
> {</v-text-field> | ||
</v-card-text> | ||
<v-divider></v-divider> | ||
<v-divider> | ||
}</v-divider> | ||
|
||
<v-card-actions> | ||
<v-spacer></v-spacer> | ||
<v-tooltip top> | ||
<template v-slot:activator="{ on, attrs }"> | ||
<v-btn color="primary" v-bind="attrs" v-on="on" text type="submit"> | ||
<v-btn v-bind="attrs" v-on="on" color="primary" type="submit" form="formLexeme"> | ||
I understand | ||
</v-btn> | ||
</template> | ||
|
@@ -53,41 +54,47 @@ export default { | |
name: 'Lexeme', | ||
props: ['wikiId', 'setting'], | ||
data () { | ||
return { | ||
const data = { | ||
valid: false, | ||
dialog: false, | ||
userConfirmationString: 'wbstack-important-change', | ||
rules: { | ||
match: (value) => | ||
value === this.userConfirmationString || 'Please enter the confirmation' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Second problem was that Also the comparison is borked and would return either There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm very unclear how this ever really worked |
||
} | ||
rules: {} | ||
} | ||
data.rules.match = (v) => { | ||
v = v && v.trim() | ||
return v === data.userConfirmationString || v === 'Please enter the confirmation' | ||
} | ||
return data | ||
}, | ||
computed: { | ||
isEnabled () { | ||
return this.$store.state.wikis.currentWikiSettings.wwExtEnableWikibaseLexeme | ||
} | ||
}, | ||
methods: { | ||
enableFeature () { | ||
toggleSetting (validationPassed) { | ||
const updatedValue = !this.isEnabled | ||
if (updatedValue === false && !validationPassed) { | ||
// disabling the features requires user confirmation | ||
// which is checked by validating the form | ||
return | ||
} | ||
|
||
const wiki = this.wikiId | ||
const setting = 'wwExtEnableWikibaseLexeme' | ||
const value = !this.isEnabled | ||
|
||
this.$store.dispatch('updateSetting', { wiki, setting, value }) | ||
.then(() => this.$store.dispatch('setLexemeEnabled', value)) | ||
this.$store.dispatch('updateSetting', { wiki, setting, value: updatedValue }) | ||
.then(() => this.$store.dispatch('setLexemeEnabled', updatedValue)) | ||
.catch(err => { | ||
console.log(err.response) | ||
alert('Something went wrong.') | ||
}) | ||
|
||
this.hideModal() | ||
}, | ||
confirmAction () { | ||
const formValidation = this.$refs.form.validate() | ||
if (formValidation) { | ||
this.enableFeature() | ||
} | ||
handleSubmit (e) { | ||
e.preventDefault() | ||
this.toggleSetting(this.$refs.form.validate()) | ||
}, | ||
hideModal () { | ||
this.dialog = false | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
First problem here would be that albeit the button is within the parent form in the template, Vue will hoist it outside of the form when rendering the modal, meaning submitting it would go nowhere as there's no associated form.
There are two solutions to the problem:
I think both is ok.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this looks nice