From 885e7d7bf4cf026ee926dadafe0b4e0b32e58de5 Mon Sep 17 00:00:00 2001 From: Ferdinand Thiessen Date: Thu, 22 Aug 2024 00:31:22 +0200 Subject: [PATCH] feat(NcDialog): Allow to catch `reset` event Sometimes it is useful to also have a reset button, we already support the native type `reset` so this allows to catch the `reset` event. Signed-off-by: Ferdinand Thiessen --- src/components/NcDialog/NcDialog.vue | 35 +++++++++++++++++++++------- 1 file changed, 27 insertions(+), 8 deletions(-) diff --git a/src/components/NcDialog/NcDialog.vue b/src/components/NcDialog/NcDialog.vue index a14acdb76b..34024a6a6a 100644 --- a/src/components/NcDialog/NcDialog.vue +++ b/src/components/NcDialog/NcDialog.vue @@ -95,6 +95,7 @@ Note that this is not possible if the dialog contains a navigation! name="Choose a name" :open.sync="showDialog" @submit="currentName = newName" + @reset="newName = ''" @closing="newName = ''"> false, + }, { label: 'Submit', type: 'primary', @@ -169,7 +176,7 @@ export default { + @click="handleButtonClose(button)" /> @@ -300,7 +307,7 @@ export default defineComponent({ }, /** - * Optionally pass additionaly classes which will be set on the navigation for custom styling + * Optionally pass additional classes which will be set on the navigation for custom styling * @default '' * @example * ```html @@ -344,7 +351,7 @@ export default defineComponent({ }, /** - * Optionally pass additionaly classes which will be set on the content wrapper for custom styling + * Optionally pass additional classes which will be set on the content wrapper for custom styling * @default '' */ contentClasses: { @@ -354,7 +361,7 @@ export default defineComponent({ }, /** - * Optionally pass additionaly classes which will be set on the dialog itself + * Optionally pass additional classes which will be set on the dialog itself * (the default `class` attribute will be set on the modal wrapper) * @default '' */ @@ -434,6 +441,16 @@ export default defineComponent({ /** Forwarded HTMLFormElement submit event (only if `is-form` is set) */ emit('submit', event) }, + /** + * @param {Event} event Form submit event + */ + reset(event) { + event.preventDefault() + /** + * Forwarded HTMLFormElement reset event (only if `is-form` is set). + */ + emit('reset', event) + } } : {}, ) @@ -447,9 +464,11 @@ export default defineComponent({ /** * Handle clicking a dialog button -> should close */ - const handleButtonClose = () => { - // Skip close if invalid dialog - if (dialogTagName.value === 'form' && !dialogElement.value.reportValidity()) { + const handleButtonClose = (button) => { + // Skip close on submit if invalid dialog + if (button.nativeType === 'submit' + && dialogTagName.value === 'form' + && !dialogElement.value.reportValidity()) { return } handleClosing()