Hi

I've found that dialog attributes that require a boolean false or true value are passed as strings from rel tag. This means that the actual value of the attributes isn't able to take effect.

To fix it, I added the following lines to simple_dialog.js. Does this sound like a decent solution?

Cheers

Luke

  // ** Convert text boolean representation to boolean **
  if(option[1]==='true') option[1]=true;
  else if(option[1]==='false') option[1]=false;

eg.

if (options[i]) {
  option = options[i].split(':');

  // ** Convert text boolean representation to boolean ** 
  if(option[1]==='true') option[1]=true;
  else if(option[1]==='false') option[1]=false;

  // If it's a position option, we may need to parse an array
  if (option[0] == 'position' && option[1].match(/\[.*,.*\]/)) {
    option[1] = option[1].match(/\[(.*)\]/)[1].split(',');
    // Check if positions need be converted to int
    if (!isNaN(parseInt(option[1][0]))) {
      option[1][0] = parseInt(option[1][0]);
    }
    if (!isNaN(parseInt(option[1][1]))) {
      option[1][1] = parseInt(option[1][1]);
    }
  }
  try {
    $('#simple-dialog-container').dialog('option', option[0], option[1]);
  } catch (err) {
    log('[error] Simple Dialog: Could not set dialog option: ' + option[0] + ' with value: ' + option[1] + '. Error: ' + err);
  }
}

http://stackoverflow.com/questions/263965/how-can-i-convert-a-string-to-...

Comments

lukus’s picture

Status: Fixed » Needs review

Actually, that doesn't work. The check needed to occur after the options are parsed for position values, because the newly created boolean values is (not)isNaN.

if (options[i]) {
  option = options[i].split(':');

  // If it's a position option, we may need to parse an array
  if (option[0] == 'position' && option[1].match(/\[.*,.*\]/)) {
    option[1] = option[1].match(/\[(.*)\]/)[1].split(',');
    // Check if positions need be converted to int
    if (!isNaN(parseInt(option[1][0]))) {
      option[1][0] = parseInt(option[1][0]);
    }
    if (!isNaN(parseInt(option[1][1]))) {
      option[1][1] = parseInt(option[1][1]);
    }
  }

  // ** Convert text boolean representation to boolean **
  if(option[1]==='true') option[1]=true;
  else if(option[1]==='false') option[1]=false;

  try {
    $('#simple-dialog-container').dialog('option', option[0], option[1]);
  } catch (err) {
    log('[error] Simple Dialog: Could not set dialog option: ' + option[0] + ' with value: ' + option[1] + '. Error: ' + err);
  }
}
drclaw’s picture

Nice catch. I'll roll this into the next commit!

drclaw’s picture

Status: Needs review » Fixed

This has been committed. Thanks!

Status: Needs review » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.