Disable inline submit button when title is blank
[ci skip]
This commit is contained in:
parent
5f2b142b66
commit
e713c68aa7
3 changed files with 32 additions and 2 deletions
|
@ -7,6 +7,10 @@
|
|||
type: Boolean,
|
||||
required: true,
|
||||
},
|
||||
formState: {
|
||||
type: Object,
|
||||
required: true,
|
||||
},
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
|
@ -14,6 +18,11 @@
|
|||
updateLoading: false,
|
||||
};
|
||||
},
|
||||
computed: {
|
||||
isSubmitEnabled() {
|
||||
return this.formState.title.trim() !== '';
|
||||
},
|
||||
},
|
||||
methods: {
|
||||
updateIssuable() {
|
||||
this.updateLoading = true;
|
||||
|
@ -38,9 +47,9 @@
|
|||
<div class="prepend-top-default append-bottom-default clearfix">
|
||||
<button
|
||||
class="btn btn-save pull-left"
|
||||
:class="{ disabled: updateLoading }"
|
||||
:class="{ disabled: updateLoading || !isSubmitEnabled }"
|
||||
type="submit"
|
||||
:disabled="updateLoading"
|
||||
:disabled="updateLoading || !isSubmitEnabled"
|
||||
@click="updateIssuable">
|
||||
Save changes
|
||||
<i
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
<title-field
|
||||
:form-state="formState" />
|
||||
<edit-actions
|
||||
:form-state="formState"
|
||||
:can-destroy="canDestroy" />
|
||||
</form>
|
||||
</template>
|
||||
|
|
|
@ -1,18 +1,26 @@
|
|||
import Vue from 'vue';
|
||||
import editActions from '~/issue_show/components/edit_actions.vue';
|
||||
import eventHub from '~/issue_show/event_hub';
|
||||
import Store from '~/issue_show/stores';
|
||||
|
||||
describe('Edit Actions components', () => {
|
||||
let vm;
|
||||
|
||||
beforeEach((done) => {
|
||||
const Component = Vue.extend(editActions);
|
||||
const store = new Store({
|
||||
titleHtml: '',
|
||||
descriptionHtml: '',
|
||||
issuableRef: '',
|
||||
});
|
||||
store.formState.title = 'test';
|
||||
|
||||
spyOn(eventHub, '$emit');
|
||||
|
||||
vm = new Component({
|
||||
propsData: {
|
||||
canDestroy: true,
|
||||
formState: store.formState,
|
||||
},
|
||||
}).$mount();
|
||||
|
||||
|
@ -41,6 +49,18 @@ describe('Edit Actions components', () => {
|
|||
});
|
||||
});
|
||||
|
||||
it('disables submit button when title is blank', (done) => {
|
||||
vm.formState.title = '';
|
||||
|
||||
Vue.nextTick(() => {
|
||||
expect(
|
||||
vm.$el.querySelector('.btn-save').getAttribute('disabled'),
|
||||
).toBe('disabled');
|
||||
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
describe('updateIssuable', () => {
|
||||
it('sends update.issauble event when clicking save button', () => {
|
||||
vm.$el.querySelector('.btn-save').click();
|
||||
|
|
Loading…
Reference in a new issue