Activate the primary dialog button on enter if there is a single input

Signed-off-by: Christopher Ng <chrng8@gmail.com>
This commit is contained in:
Christopher Ng 2022-05-27 22:02:01 +00:00
parent edba92d1f4
commit 9f09caaaea
3 changed files with 18 additions and 3 deletions

View file

@ -56,6 +56,21 @@ $.widget('oc.ocdialog', {
this.$dialog.append(this.element.detach())
this.element.removeAttr('title').addClass('oc-dialog-content').appendTo(this.$dialog)
// Activate the primary button on enter if there is a single input
if (self.element.find('input').length === 1) {
const $input = self.element.find('input')
$input.on('keydown', function(event) {
if (event.key === 'Enter') {
if (self.$buttonrow) {
const $button = self.$buttonrow.find('button.primary')
if ($button && !$button.prop('disabled')) {
$button.click()
}
}
}
})
}
this.$dialog.css({
display: 'inline-block',
position: 'fixed',

4
dist/core-main.js vendored

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long