Commit 44c01ecc authored by Simon Knox's avatar Simon Knox

submit form on enter key. disable button when field empty

parent 834cc1b8
<script> <script>
/* global BoardService */ /* global BoardService */
/* global Flash */
import Flash from '~/flash';
import PopupDialog from '~/vue_shared/components/popup_dialog.vue'; import PopupDialog from '~/vue_shared/components/popup_dialog.vue';
import BoardMilestoneSelect from './milestone_select.vue'; import BoardMilestoneSelect from './milestone_select.vue';
import BoardWeightSelect from './weight_select.vue'; import BoardWeightSelect from './weight_select.vue';
...@@ -65,7 +65,7 @@ export default { ...@@ -65,7 +65,7 @@ export default {
currentPage: Store.state.currentPage, currentPage: Store.state.currentPage,
milestones: [], milestones: [],
milestoneDropdownOpen: false, milestoneDropdownOpen: false,
submitDisabled: false, isLoading: false,
}; };
}, },
components: { components: {
...@@ -127,18 +127,22 @@ export default { ...@@ -127,18 +127,22 @@ export default {
weightsArray() { weightsArray() {
return JSON.parse(this.weights); return JSON.parse(this.weights);
}, },
submitDisabled() {
return this.isLoading || this.board.name.length === 0;
},
}, },
methods: { methods: {
submit() { submit() {
if (this.board.name.length === 0) return;
this.isLoading = true;
if (this.isDeleteForm) { if (this.isDeleteForm) {
this.submitDisabled = true;
gl.boardService.deleteBoard(this.currentBoard) gl.boardService.deleteBoard(this.currentBoard)
.then(() => { .then(() => {
gl.utils.visitUrl(Store.rootPath); gl.utils.visitUrl(Store.rootPath);
}) })
.catch(() => { .catch(() => {
Flash('Failed to delete board. Please try again.'); Flash('Failed to delete board. Please try again.');
this.submitDisabled = false; this.isLoading = false;
}); });
} else { } else {
gl.boardService.createBoard(this.board) gl.boardService.createBoard(this.board)
...@@ -148,6 +152,7 @@ export default { ...@@ -148,6 +152,7 @@ export default {
}) })
.catch(() => { .catch(() => {
Flash('Unable to save your changes. Please try again.'); Flash('Unable to save your changes. Please try again.');
this.isLoading = false;
}); });
} }
}, },
...@@ -191,6 +196,7 @@ export default { ...@@ -191,6 +196,7 @@ export default {
<form <form
v-else v-else
class="js-board-config-modal" class="js-board-config-modal"
@submit.prevent
> >
<div <div
v-if="!readonly" v-if="!readonly"
...@@ -208,6 +214,7 @@ export default { ...@@ -208,6 +214,7 @@ export default {
type="text" type="text"
id="board-new-name" id="board-new-name"
v-model="board.name" v-model="board.name"
@keyup.enter="submit"
placeholder="Enter board name" placeholder="Enter board name"
> >
</div> </div>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment