Skip to content

Commit

Permalink
enter to submit date
Browse files Browse the repository at this point in the history
  • Loading branch information
sgratzl committed Apr 15, 2020
1 parent 8b52a89 commit 84a85ad
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 7 deletions.
18 changes: 11 additions & 7 deletions src/ui/dialogs/ADialog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,13 +144,7 @@ abstract class ADialog {
this.node.onsubmit = (evt) => {
evt.stopPropagation();
evt.preventDefault();
if (!this.node.checkValidity()) {
return false;
}
if (this.submit() !== false) {
this.destroy('confirm');
}
return false;
return this.triggerSubmit();
};
const cancel = this.find<HTMLButtonElement>('button[title=Cancel]');
if (cancel) {
Expand All @@ -171,6 +165,16 @@ abstract class ADialog {
this.dialog.manager.push(this);
}

protected triggerSubmit() {
if (!this.node.checkValidity()) {
return false;
}
if (this.submit() !== false) {
this.destroy('confirm');
}
return false;
}

protected find<T extends HTMLElement>(selector: string): T {
return <T>this.node.querySelector(selector);
}
Expand Down
6 changes: 6 additions & 0 deletions src/ui/dialogs/InputDateDialog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ export default class InputDateDialog extends APopup {
node.insertAdjacentHTML('beforeend', `
<input type="date" value="${o.value ? f(o.value) : ''}" required autofocus placeholder="${o.label ? o.label : 'enter date'}">
`);
this.findInput('input[type=date]').addEventListener('keypress', (evt) => {
if (evt.key === 'Enter') {
this.triggerSubmit();
}
});
this.enableLivePreviews('input');
}

submit() {
Expand Down
1 change: 1 addition & 0 deletions src/ui/dialogs/InputNumberDialog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export default class InputNumberDialog extends APopup {
node.insertAdjacentHTML('beforeend', `
<input type="number" value="${isNaN(o.value) ? '' : String(o.value)}" required autofocus placeholder="${o.label ? o.label : 'enter number'}" ${isNaN(o.min) ? '' : ` min="${o.min}"`} ${isNaN(o.max) ? '' : ` max="${o.max}"`} step="${o.step}">
`);
this.enableLivePreviews('input');
}

submit() {
Expand Down

0 comments on commit 84a85ad

Please sign in to comment.