Leaving the confirmation message field empty on the settings page doesn't seem to be working correctly. I'm seeing an array of empty strings being set in my Drupal settings.

jQuery.extend(Drupal.settings, { "basePath": "/secure/programreview/", "field_button_submit-1803": { "confirmation": [ "", "" ] }, "activePath": "/secure/programreview/", "getQ": "node/1803" });

We put a few debug statements in the module and saw that drupal_add_js($settings, 'setting'); is being called twice.

As a quick fix, we changed

Drupal.settings[id].confirmation

to

$.isArray(Drupal.settings[id].confirmation) ? Drupal.settings[id].confirmation[0] : Drupal.settings[id].confirmation;

I looked through previous issues, but those all seem to be caused by other messaging modules interfering and we aren't using any.

Comments

FranckV’s picture

Hi sprinkles, thank you for the quick fix proposal. I have the exact same issue. However, I don't really understand your final code. Sorry...

The pattern Drupal.settings[id].confirmation is only available in the last three lines of the button_field.js code :

Drupal.behaviors.buttonFieldBehavior = function(context) {
  $('.button_field', context).bind('click', function(e) {
    var id = $(this).attr('id'),
      process = true;
    
    // if a confirmation message was provided then display it now
    if (Drupal.settings[id].confirmation) {
      process = confirm(Drupal.settings[id].confirmation);
    } // end if a confirmation message was provided

But I can't make it work... What would the corrected code look like ?
Thanks

sprinkles’s picture

We changed the code you posted to the following:

Drupal.behaviors.buttonFieldBehavior = function(context) {
  $('.button_field', context).bind('click', function(e) {
    var id = $(this).attr('id'),
      process = true;

    // if a confirmation message was provided then display it now
    var conf = $.isArray(Drupal.settings[id].confirmation) ? Drupal.settings[id].confirmation[0] : Drupal.settings[id].confirmation;

    if (conf) {
      process = confirm(conf);
    } // end if a confirmation message was provided

I put it in a variable to make it easier to read.

Also, I suggested that it's a "quick fix" because this isn't really solving the problem. The way the confirmation message is being set to begin with possibly needs some work in the module code.

BassistJimmyJam’s picture

Status: Active » Closed (fixed)

The confirmation should always be a string and never an array, so doing an isArray() check is not necessary. I have not been able to reproduce your issue; however, I have made some changes in f6128dc that should ensure the confirmation message is never shown when it is not set.

tbroberg’s picture

We had this issue, and the fixes introduced in the 3/26 6.x-1.x-dev seem to have resolved it.

Thanks, BJJ.

- Tim.