Skip to content

Commit 09a0041

Browse files
authored
Fix areYouSure confirm (#32941)
See the comment
1 parent 23687a0 commit 09a0041

File tree

4 files changed

+12
-4
lines changed

4 files changed

+12
-4
lines changed

web_src/js/features/common-fetch-action.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {showErrorToast} from '../modules/toast.ts';
33
import {addDelegatedEventListener, submitEventSubmitter} from '../utils/dom.ts';
44
import {confirmModal} from './comp/ConfirmModal.ts';
55
import type {RequestOpts} from '../types.ts';
6+
import {ignoreAreYouSure} from '../vendor/jquery.are-you-sure.ts';
67

78
const {appSubUrl, i18n} = window.config;
89

@@ -27,7 +28,7 @@ async function fetchActionDoRequest(actionElem: HTMLElement, url: string, opt: R
2728
if (resp.status === 200) {
2829
let {redirect} = await resp.json();
2930
redirect = redirect || actionElem.getAttribute('data-redirect');
30-
actionElem.classList.remove('dirty'); // remove the areYouSure check before reloading
31+
ignoreAreYouSure(actionElem); // ignore the areYouSure check before reloading
3132
if (redirect) {
3233
fetchActionDoRedirect(redirect);
3334
} else {

web_src/js/features/repo-editor.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {attachRefIssueContextPopup} from './contextpopup.ts';
66
import {POST} from '../modules/fetch.ts';
77
import {initDropzone} from './dropzone.ts';
88
import {confirmModal} from './comp/ConfirmModal.ts';
9-
import {applyAreYouSure} from '../vendor/jquery.are-you-sure.ts';
9+
import {applyAreYouSure, ignoreAreYouSure} from '../vendor/jquery.are-you-sure.ts';
1010
import {fomanticQuery} from '../modules/fomantic/base.ts';
1111

1212
function initEditPreviewTab(elForm: HTMLFormElement) {
@@ -188,7 +188,7 @@ export function initRepoEditor() {
188188
header: elForm.getAttribute('data-text-empty-confirm-header'),
189189
content: elForm.getAttribute('data-text-empty-confirm-content'),
190190
})) {
191-
elForm.classList.remove('dirty');
191+
ignoreAreYouSure(elForm);
192192
elForm.submit();
193193
}
194194
}

web_src/js/features/repo-issue.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import {GET, POST} from '../modules/fetch.ts';
1616
import {showErrorToast} from '../modules/toast.ts';
1717
import {initRepoIssueSidebar} from './repo-issue-sidebar.ts';
1818
import {fomanticQuery} from '../modules/fomantic/base.ts';
19+
import {ignoreAreYouSure} from '../vendor/jquery.are-you-sure.ts';
1920

2021
const {appSubUrl} = window.config;
2122

@@ -578,7 +579,7 @@ export function initRepoIssueTitleEdit() {
578579
}
579580
}
580581
}
581-
issueTitleEditor.classList.remove('dirty');
582+
ignoreAreYouSure(issueTitleEditor);
582583
window.location.reload();
583584
} catch (error) {
584585
console.error(error);

web_src/js/vendor/jquery.are-you-sure.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,3 +204,9 @@ export function applyAreYouSure(selectorOrEl: string|Element|$, opts = {}) {
204204
export function reinitializeAreYouSure(selectorOrEl: string|Element|$) {
205205
$(selectorOrEl).trigger('reinitialize.areYouSure');
206206
}
207+
208+
export function ignoreAreYouSure(selectorOrEl: string|Element|$) {
209+
// here we should only add "ignore-dirty" but not remove "dirty".
210+
// because when using "enter" to submit a form, the "dirty" class will appear again before reloading.
211+
$(selectorOrEl).addClass('ignore-dirty');
212+
}

0 commit comments

Comments
 (0)