mirror of
https://github.com/MarijnDoeve/TijdVoorDeTest.git
synced 2026-07-06 23:50:16 +02:00
feat: add bank question via modal + dirty modal guard
- Add question in question bank now opens a modal instead of navigating to a full-page form, consistent with the edit modal pattern - Modal closes are blocked by static backdrop once the user has made any change (input, checkbox, drag-reorder, sort, randomize, remove answer) - Dirty state resets when the modal is fully hidden
This commit is contained in:
@@ -23,9 +23,29 @@ export default class extends Controller {
|
||||
const res = await fetch(url, {headers: {'X-Modal-Request': '1'}});
|
||||
this.modalBodyTarget.innerHTML = await res.text();
|
||||
this._moveFooter();
|
||||
this._bindDirty();
|
||||
this._bindForm(url);
|
||||
}
|
||||
|
||||
_bindDirty() {
|
||||
const modal = Modal.getOrCreateInstance(this.modalTarget);
|
||||
modal._config.backdrop = true;
|
||||
modal._config.keyboard = true;
|
||||
|
||||
const markDirty = () => {
|
||||
modal._config.backdrop = 'static';
|
||||
modal._config.keyboard = false;
|
||||
};
|
||||
|
||||
this.modalBodyTarget.addEventListener('input', markDirty, {once: true});
|
||||
this.modalBodyTarget.addEventListener('change', markDirty, {once: true});
|
||||
|
||||
this.modalTarget.addEventListener('hidden.bs.modal', () => {
|
||||
modal._config.backdrop = true;
|
||||
modal._config.keyboard = true;
|
||||
}, {once: true});
|
||||
}
|
||||
|
||||
_moveFooter() {
|
||||
if (!this.hasModalFooterTarget) return;
|
||||
const template = this.modalBodyTarget.querySelector('template[data-modal-footer]');
|
||||
|
||||
Reference in New Issue
Block a user