Skip to content
Snippets Groups Projects
Unverified Commit 687c698e authored by Thomas's avatar Thomas Committed by GitHub
Browse files

Merge pull request #100 from h5p/add-cancel-callback-for-editor-form

Add cancel submit callback for h5p editor form
parents df63b962 40174e4b
Branches
No related tags found
No related merge requests found
(function ($, ns) { (function ($, ns) {
H5PEditor.init = function ($form, $type, $upload, $create, $editor, $library, $params, $maxScore, $title, submitCallback) { H5PEditor.init = function ($form, $type, $upload, $create, $editor, $library, $params, $maxScore, $title, cancelSubmitCallback) {
H5PEditor.$ = H5P.jQuery; H5PEditor.$ = H5P.jQuery;
H5PEditor.basePath = H5PIntegration.editor.libraryUrl; H5PEditor.basePath = H5PIntegration.editor.libraryUrl;
H5PEditor.fileIcon = H5PIntegration.editor.fileIcon; H5PEditor.fileIcon = H5PIntegration.editor.fileIcon;
...@@ -49,11 +49,17 @@ ...@@ -49,11 +49,17 @@
// Duplicate the submit button input because it is not posted when calling $form.submit() // Duplicate the submit button input because it is not posted when calling $form.submit()
const $submitters = $form.find('input[type="submit"]'); const $submitters = $form.find('input[type="submit"]');
let isCanceling = false;
$submitters.click(function () { $submitters.click(function () {
// Create hidden input and give it the value // Create hidden input and give it the value
const name = $(this).prop('name'); const name = $(this).prop('name');
const value = $(this).prop('value'); const value = $(this).prop('value');
$('<input type="hidden" name="' + name + '" value="' + value + '" />').appendTo($form); $('<input type="hidden" name="' + name + '" value="' + value + '" />').appendTo($form);
// Allow caller to cancel validation and submission of form on button click
if (cancelSubmitCallback) {
isCanceling = cancelSubmitCallback($(this));
}
}); });
let formIsUpdated = false; let formIsUpdated = false;
...@@ -62,6 +68,10 @@ ...@@ -62,6 +68,10 @@
return; // Old file upload return; // Old file upload
} }
if (isCanceling) {
return;
}
if (h5peditor !== undefined && !formIsUpdated) { if (h5peditor !== undefined && !formIsUpdated) {
// Get content from editor // Get content from editor
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment