mirror of
https://github.com/BookStackApp/BookStack.git
synced 2025-07-28 17:02:04 +03:00
Lexical: Range of fixes
- Prevented ui shortcuts running in editor - Added form modal closing on submit - Fixed ability to escape lists via enter on empty last item
This commit is contained in:
@ -72,6 +72,7 @@ export class EditorFormField extends EditorUiElement {
|
||||
export class EditorForm extends EditorContainerUiElement {
|
||||
protected definition: EditorFormDefinition;
|
||||
protected onCancel: null|(() => void) = null;
|
||||
protected onSuccessfulSubmit: null|(() => void) = null;
|
||||
|
||||
constructor(definition: EditorFormDefinition) {
|
||||
let children: (EditorFormField|EditorUiElement)[] = definition.fields.map(fieldDefinition => {
|
||||
@ -98,6 +99,10 @@ export class EditorForm extends EditorContainerUiElement {
|
||||
this.onCancel = callback;
|
||||
}
|
||||
|
||||
setOnSuccessfulSubmit(callback: () => void) {
|
||||
this.onSuccessfulSubmit = callback;
|
||||
}
|
||||
|
||||
protected getFieldByName(name: string): EditorFormField|null {
|
||||
|
||||
const search = (children: EditorUiElement[]): EditorFormField|null => {
|
||||
@ -128,10 +133,13 @@ export class EditorForm extends EditorContainerUiElement {
|
||||
])
|
||||
]);
|
||||
|
||||
form.addEventListener('submit', (event) => {
|
||||
form.addEventListener('submit', async (event) => {
|
||||
event.preventDefault();
|
||||
const formData = new FormData(form as HTMLFormElement);
|
||||
this.definition.action(formData, this.getContext());
|
||||
const result = await this.definition.action(formData, this.getContext());
|
||||
if (result && this.onSuccessfulSubmit) {
|
||||
this.onSuccessfulSubmit();
|
||||
}
|
||||
});
|
||||
|
||||
cancelButton.addEventListener('click', (event) => {
|
||||
|
Reference in New Issue
Block a user