Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

patches table widget to send values on locale switch #34

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 35 additions & 1 deletion assets/js/multilingual.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Multi lingual control plugin
*
*
* Data attributes:
* - data-control="multilingual" - enables the plugin on an element
* - data-default-locale="en" - default locale code
Expand Down Expand Up @@ -140,6 +140,40 @@
// ===============
$(document).render(function () {
$('[data-control="multilingual"]').multiLingual()
patchTableWidget()
})

var tablePatched = false;

function patchTableWidget() {
if ($.wn.table && $.wn.table.table && !tablePatched) {
var tableOnFormSubmit = $.wn.table.table.prototype.onFormSubmit

$.wn.table.table.prototype.onFormSubmit = function(ev, data) {
if (data.handler.indexOf('onSwitchItemLocale') &&
(
$(this.el).parents('[data-control="mlrepeater"]').length ||
$(this.el).parents('[data-control="mlnestedform"]').length
)
) {
// temporary override postback handler name
var postbackHandlerName = this.options.postbackHandlerName;
this.options.postbackHandlerName = data.handler;

// now call submit handler with new postback handler
var result = tableOnFormSubmit.call(this, ev, data);

// reset to previous value
this.options.postbackHandlerName = postbackHandlerName;

return result;
}

return tableOnFormSubmit.call(this, ev, data)
};

tablePatched = true;
}
}

}(window.jQuery);