diff -u b/core/misc/dialog.ajax.js b/core/misc/dialog.ajax.js --- b/core/misc/dialog.ajax.js +++ b/core/misc/dialog.ajax.js @@ -24,9 +24,10 @@ if ($dialog.length) { // Remove and replace the dialog buttons with those from the new form. if ($dialog.dialog('option', 'drupalAutoButtons')) { - var buttons = Drupal.behaviors.dialog.prepareDialogButtons($dialog); - $dialog.dialog('option', 'buttons', buttons); + // Trigger an event to detect/sync changes to buttons. + $dialog.trigger('dialogButtonsChange'); } + // Refocus the first input element after validation errors. if ($context.find('form').length) { $context.find('input:first').focus(); @@ -98,6 +99,12 @@ response.dialogOptions.buttons = Drupal.behaviors.dialog.prepareDialogButtons($dialog); } + // Bind dialogButtonsChange + $dialog.on('dialogButtonsChange', function() { + var buttons = Drupal.behaviors.dialog.prepareDialogButtons($dialog); + $dialog.dialog('option', 'buttons', buttons); + }); + // Open the dialog itself. response.dialogOptions = response.dialogOptions || {}; var dialog = Drupal.dialog($dialog, response.dialogOptions); @@ -123,8 +130,8 @@ Drupal.dialog($dialog).close(); } - // Add the standard Drupal class for buttons for style consistency. - $dialog.parent().find('.ui-dialog-buttonset').addClass('form-actions'); + // Unbind dialogButtonsChange + $dialog.off('dialogButtonsChange'); }; /** diff -u b/core/modules/views_ui/js/views-admin.js b/core/modules/views_ui/js/views-admin.js --- b/core/modules/views_ui/js/views-admin.js +++ b/core/modules/views_ui/js/views-admin.js @@ -164,12 +164,14 @@ attach: function (context) { var $context = $(context); // The add item form may have an id of views-ui-add-item-form--n. - if ($context.is('form[id^="views-ui-add-item-form"]')) { - // Make sure we don't add more than one event handler to the same form. - var $form = $context.once('views-ui-add-item-form'); - if ($form.length) { - new Drupal.viewsUi.AddItemForm($form); - } + var $form = $context.is('form[id^="views-ui-add-item-form"]') ? + $context.once('views-ui-add-item-form') : + // In some case this can be wrapped or contain other elements. + $context.find('form[id^="views-ui-add-item-form"]').once('views-ui-add-item-form'); + + // If we we have an unprocessed views-ui-add-item-form, let's instantiate. + if ($form.length) { + new Drupal.viewsUi.AddItemForm($form); } } }; @@ -869,7 +871,8 @@ attach: function (context) { $(context).find('#edit-override-dropdown').once('views-ui-override-button-text', function () { // Closures! :( - var $submit = $('#edit-submit'); + var $context = $(context); + var $submit = $context.find('#edit-submit'); var old_value = $submit.val(); $submit.once('views-ui-override-button-text') @@ -889,6 +892,8 @@ else { $submit.val(Drupal.t('Apply (this display)')); } + var $dialog = $context.closest('.ui-dialog-content'); + $dialog.trigger('dialogButtonsChange'); }) .trigger('change'); });