Search code examples
facebookfbjs

End line "\n" in FBJS Dialog


I'm trying to show a FBJS Dialog with a multiline message.

message += "Please enter the name of the Post.\n"
message += "Please enter content.\n"
message += "Content must have at least 10 characters.";

new Dialog().showMessage("Error", message);

But that piece of code shows the message in the same line.

Does anybody knows how to do that?

Thanks. Ernesto Carrión


Solution

  • You should use an fb:js-string when you have something other than text to show in a dialog.

    Here's an example:

    <fb:js-string var="messageToShow">
      Here's some text.<br />
      and some more text...<br />
      <p>You can even have HTML or FBML tags in here!</p>
      <img src="http://absolute.path.to/the/image.jpg" />
      <form id="selectFriendForm">
        <label class="RedLabel">Select a friend:</label>
        <fb:friend-selector name="uid" idname="selected_friend" />
      </form>
    </fb:js-string>
    

    And then you have the function that shows the dialog:

    <script type="text/javascript">
      function showDialog() {
        var dialog = new Dialog(Dialog.DIALOG_POP);
            dialog.showChoice('Select a friend',
            messageToShow, // fb:js-string var name
            button_confirm = 'Choose this friend',
            button_cancel = 'Cancel'
          );
    
        dialog.onconfirm = function() {
          var formData = document.getElementById('selectFriendForm').serialize();
          // ajax call to save my selected friend or whatever
        }
      }
    </script>