Skip to content
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

Enter key submits form #7968

Merged
merged 3 commits into from
Nov 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Enhancement: Group and user creation forms submit on enter

Group and User creation forms can now be submitted by pressing enter.

https://github.com/owncloud/web/pull/7968
https://github.com/owncloud/web/issues/7937
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
:title="$gettext('Create group')"
:button-cancel-text="$gettext('Cancel')"
:button-confirm-text="$gettext('Create')"
:button-confirm-disabled="buttonConfirmDisabled"
:button-confirm-disabled="isFormInvalid"
focus-trap-initial="#create-group-input-display-name"
@cancel="$emit('cancel')"
@confirm="$emit('confirm', group)"
>
<template #content>
<form autocomplete="off">
<form autocomplete="off" @submit.prevent="onFormSubmit">
<oc-text-input
id="create-group-input-display-name"
v-model="group.displayName"
Expand All @@ -19,6 +19,7 @@
:fix-message-line="true"
@input="validateDisplayName"
/>
<input type="submit" class="oc-hidden" />
</form>
</template>
</oc-modal>
Expand Down Expand Up @@ -50,7 +51,7 @@ export default {
}
},
computed: {
buttonConfirmDisabled() {
isFormInvalid() {
return Object.keys(this.formData)
.map((k) => !!this.formData[k].valid)
.includes(false)
Expand Down Expand Up @@ -80,6 +81,12 @@ export default {
this.formData.displayName.errorMessage = ''
this.formData.displayName.valid = true
return true
},
onFormSubmit() {
if (this.isFormInvalid) {
return
}
this.$emit('confirm', this.group)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
:title="$gettext('Create user')"
:button-cancel-text="$gettext('Cancel')"
:button-confirm-text="$gettext('Create')"
:button-confirm-disabled="buttonConfirmDisabled"
:button-confirm-disabled="isFormInvalid"
focus-trap-initial="#create-user-input-display-name"
@cancel="$emit('cancel')"
@confirm="$emit('confirm', user)"
>
<template #content>
<form autocomplete="off">
<form autocomplete="off" @submit.prevent="onFormSubmit">
<oc-text-input
id="create-user-input-display-name"
v-model="user.onPremisesSamAccountName"
Expand Down Expand Up @@ -46,6 +46,7 @@
:fix-message-line="true"
@input="validatePassword"
/>
<input type="submit" class="oc-hidden" />
</form>
</template>
</oc-modal>
Expand Down Expand Up @@ -96,7 +97,7 @@ export default {
}
},
computed: {
buttonConfirmDisabled() {
isFormInvalid() {
return Object.keys(this.formData)
.map((k) => !!this.formData[k].valid)
.includes(false)
Expand Down Expand Up @@ -149,7 +150,6 @@ export default {
this.formData.userName.valid = true
return true
},

validateDisplayName() {
this.formData.displayName.valid = false

Expand All @@ -162,7 +162,6 @@ export default {
this.formData.displayName.valid = true
return true
},

validateEmail() {
this.formData.email.valid = false

Expand All @@ -186,6 +185,12 @@ export default {
this.formData.password.errorMessage = ''
this.formData.password.valid = true
return true
},
onFormSubmit() {
if (this.isFormInvalid) {
return
}
this.$emit('confirm', this.user)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,19 @@ localVue.use(Vuex)
afterEach(() => jest.clearAllMocks())

describe('CreateGroupModal', () => {
describe('computed method "buttonConfirmDisabled"', () => {
describe('computed method "isFormInvalid"', () => {
it('should be true if any data set is invalid', () => {
const wrapper = getWrapper()
wrapper.vm.formData.displayName.valid = false
expect(wrapper.vm.buttonConfirmDisabled).toBeTruthy()
expect(wrapper.vm.isFormInvalid).toBeTruthy()
})
})
it('should be false if no data set is invalid', () => {
const wrapper = getWrapper()
Object.keys(wrapper.vm.formData).forEach((key) => {
wrapper.vm.formData[key].valid = true
})
expect(wrapper.vm.buttonConfirmDisabled).toBeFalsy()
expect(wrapper.vm.isFormInvalid).toBeFalsy()
})

describe('method "validateDisplayName"', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,19 @@ localVue.use(Vuex)
afterEach(() => jest.clearAllMocks())

describe('CreateUserModal', () => {
describe('computed method "buttonConfirmDisabled"', () => {
describe('computed method "isFormInvalid"', () => {
it('should be true if any data set is invalid', () => {
const wrapper = getWrapper()
wrapper.vm.formData.userName.valid = false
expect(wrapper.vm.buttonConfirmDisabled).toBeTruthy()
expect(wrapper.vm.isFormInvalid).toBeTruthy()
})
})
it('should be false if no data set is invalid', () => {
const wrapper = getWrapper()
Object.keys(wrapper.vm.formData).forEach((key) => {
wrapper.vm.formData[key].valid = true
})
expect(wrapper.vm.buttonConfirmDisabled).toBeFalsy()
expect(wrapper.vm.isFormInvalid).toBeFalsy()
})

describe('method "validateUserName"', () => {
Expand Down