Skip to content

Commit

Permalink
Fixed submit handlers not being executed on modal form
Browse files Browse the repository at this point in the history
This is a regression from the #5312, submitting form with jQuery
doesn't run event handlers that are attached with `addEventListener`,
e.g Django's `filter_horizontal` field.

Ref: #5590
  • Loading branch information
vxsx committed Aug 11, 2016
1 parent 5a7169c commit cf46814
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 11 deletions.
10 changes: 5 additions & 5 deletions CHANGELOG.txt
Expand Up @@ -8,11 +8,6 @@
* Changed cache-busting implementation, it is now handled by a path change,
not by GET parameter.
* Added a possibility to copy pages in the Page Tree by drag'n'drop.
* Fixed a bug where it wasn't possible to scroll the toolbar menu if scroll
started on the disabled menu item on small screens.
* Fixed a regression when standalone CMS Widgets wouldn't work due to
non-existing JavaScript dependencies.
* Fixed a possible recursion error when using the ``Alias`` plugin.
* Make it possible to use multi-table inheritance for Page/Title extensions.
* Refactored plugin rendering functionality to speed up loading time in both
structure and content mode.
Expand All @@ -23,6 +18,11 @@
* Fixed a bug where it wasn't possible to scroll the toolbar menu if scroll
started on the disabled menu item on small screens.
* Fixed a migration error (0014) that occurred under certain environments.
* Fixed a regression when standalone CMS Widgets wouldn't work due to
non-existing JavaScript dependencies.
* Fixed a possible recursion error when using the ``Alias`` plugin.
* Fixed a regression where submit handlers for modal form wouldn't be executed
under certain circumstances


=== 3.3.1 (2016-07-13) ===
Expand Down
6 changes: 3 additions & 3 deletions cms/static/cms/js/dist/3.3.0/bundle.toolbar.min.js

Large diffs are not rendered by default.

15 changes: 14 additions & 1 deletion cms/static/cms/js/modules/cms.modal.js
Expand Up @@ -802,7 +802,20 @@ var Modal = new Class({
// as we are inside an iframe and magic is happening
item[0].click();
} else {
frm.submit();
// have to dispatch native submit event so all the submit handlers
// can be fired, see #5590
var evt = document.createEvent('HTMLEvents');

evt.initEvent('submit', false, true);
if (frm[0].dispatchEvent(evt)) {
// triggering submit event in webkit based browsers won't
// actually submit the form, while in Gecko-based ones it
// will and calling frm.submit() would throw NS_ERROR_UNEXPECTED
try {
frm[0].submit();
} catch (err) {
}
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion cms/templates/cms/wizards/create.html
Expand Up @@ -19,7 +19,7 @@ <h1>{% trans "Create" %} {{ wizard_entry.title }}</h1>
{% include "cms/wizards/includes/form_fields.html" %}
</div>
<div class="submit-row">
<input type="submit" class="cms-btn cms-btn-action" value="{% trans "Create" %}">
<input type="submit" class="default cms-btn cms-btn-action" value="{% trans "Create" %}">
<button type="submit" name="wizard_goto_step"
class="cms-btn cms-btn-secondary cms-btn-group" value="{{ wizard.steps.prev }}">
{% trans "Back" %}
Expand Down
2 changes: 1 addition & 1 deletion cms/templates/cms/wizards/start.html
Expand Up @@ -27,7 +27,7 @@ <h1>{% trans "Create" %}</h1>
{% endfor %}
</div>
<div class="submit-row">
<input type="submit" value="{% trans 'Next' %}" class="cms-btn cms-btn-action" name="_continue">
<input type="submit" value="{% trans 'Next' %}" class="default cms-btn cms-btn-action" name="_continue">
</div>
</form>
{% endblock %}

0 comments on commit cf46814

Please sign in to comment.