|
26 | 26 | window.patternkitEditor.getEditor(response.selector).setValue(response.value); |
27 | 27 | }; |
28 | 28 |
|
29 | | - // This forces Drupal to re-attach |
30 | | - $(window).on('dialog:afterclose', function (e, dialog, $element) { |
31 | | - Drupal.attachBehaviors(); |
32 | | - }); |
33 | | - |
34 | 29 | var saveSchema = function () { |
35 | 30 | $('#schema_instance_config').val(JSON.stringify(window.patternkitEditor.getValue())); |
36 | 31 | if (window.M) { |
|
286 | 281 | } |
287 | 282 | }); |
288 | 283 | window.patternkitEditor.on('change', saveSchema); |
289 | | - $('[data-drupal-selector="edit-actions-submit"]').on('input', function (e) { |
290 | | - saveSchema(); |
291 | | - }); |
292 | 284 | // Drupal triggers Ajax submit via input events. |
293 | 285 | // This is before allowing other events, so we need to add a pre-hook |
294 | 286 | // to trigger the editor update with latest field values. |
295 | 287 | // @TODO Add handling for AJAX errors and re-attach. |
296 | | - $('#edit-actions-submit').parent().submit(function (e) { |
297 | | - e.preventDefault(); |
298 | | - window.patternkitEditor.disable(); |
299 | | - saveSchema(); |
300 | | - window.patternkitEditor.destroy(); |
301 | | - $(this).unbind('submit').submit(); |
| 288 | + var parent_call = Drupal.Ajax.prototype.beforeSubmit; |
| 289 | + Drupal.Ajax.prototype.beforeSubmit = function (formValues, elementSettings, options) { |
| 290 | + debugger; |
| 291 | + if (window.patternkitEditor) { |
| 292 | + window.patternkitEditor.disable(); |
| 293 | + saveSchema(); |
| 294 | + var index = formValues.findIndex(function (o) { return o.name == "settings[instance_config]"; }); |
| 295 | + formValues[index] = { |
| 296 | + name: "settings[instance_config]", |
| 297 | + value: JSON.stringify(window.patternkitEditor.getValue()), |
| 298 | + type: "hidden", |
| 299 | + required: false |
| 300 | + }; |
| 301 | + window.patternkitEditor.destroy() |
| 302 | + } |
| 303 | + parent_call.call(this, formValues, elementSettings, options); |
| 304 | + } |
| 305 | + $('[data-drupal-selector="edit-actions-submit"]').parent('form').once().each(function () { |
| 306 | + $(this).submit(function (e) { |
| 307 | + e.preventDefault(); |
| 308 | + window.patternkitEditor.disable(); |
| 309 | + saveSchema(); |
| 310 | + window.patternkitEditor.destroy(); |
| 311 | + $(this).unbind('submit').submit(); |
| 312 | + }); |
302 | 313 | }); |
303 | 314 | }); |
304 | 315 | } |
|
0 commit comments