Forum Discussion

gwolfe's avatar
05-16-2024
Solved

Add Comments to Blox

This may be a stupid question, but how to I add comments to the Blox editor? 

// and /* */ both seem to work as I edit the script. However, after hitting "Apply" and returning to the editor my comments disappear. 

Some of our scripts get really long and comments would be helpful. 

Thanks, 

  • Hi gwolfe,

    In testing in the Blox editor, using opening and terminating comment syntax (/* */) worked without issue:

     

     

    {
        "style": "",
        "script": "/* Test Comment */ console.log('Test'); /* Test Comment2 */ console.log('Second Test'); /* Test Comment3 */ console.log('Third Test');",
        "title": "",
        "showCarousel": true,
        "body": [
            {
                "type": "Container",
                "items": [
                    {
                        "type": "TextBlock",
                        "text": "❤️️ Welcome to BloX ❤️️",
                        "style": {
                            "text-align": "center",
                            "font-weight": "bold",
                            "font-size": "24px",
                            "margin": "100px"
                        }
                    }
                ]
            }
        ],
        "actions": []
    }

     

     

    Unfortunately, what was not saved by Blox was starting a new line in the script parameter in the Blox template, which was not accepted as valid by Blox, and all changes after using a new line character were lost.

     

    For a more readable script editor UI, using the native Script Editor UI and widget events, are preferred, in the script editor there is no limitation on formatting of the script or how many lines the script uses. 

     

    Alternatively, the code can be edited in a text editor/IDE with new lines present for readability, and when finished pasted in a single line when finished. Using the opening and terminating comment syntax (/* */) will work for comments.

     

    .

4 Replies

  • JeremyFriedel's avatar
    JeremyFriedel
    Sisense Employee

    Hi gwolfe,

    In testing in the Blox editor, using opening and terminating comment syntax (/* */) worked without issue:

     

     

    {
        "style": "",
        "script": "/* Test Comment */ console.log('Test'); /* Test Comment2 */ console.log('Second Test'); /* Test Comment3 */ console.log('Third Test');",
        "title": "",
        "showCarousel": true,
        "body": [
            {
                "type": "Container",
                "items": [
                    {
                        "type": "TextBlock",
                        "text": "❤️️ Welcome to BloX ❤️️",
                        "style": {
                            "text-align": "center",
                            "font-weight": "bold",
                            "font-size": "24px",
                            "margin": "100px"
                        }
                    }
                ]
            }
        ],
        "actions": []
    }

     

     

    Unfortunately, what was not saved by Blox was starting a new line in the script parameter in the Blox template, which was not accepted as valid by Blox, and all changes after using a new line character were lost.

     

    For a more readable script editor UI, using the native Script Editor UI and widget events, are preferred, in the script editor there is no limitation on formatting of the script or how many lines the script uses. 

     

    Alternatively, the code can be edited in a text editor/IDE with new lines present for readability, and when finished pasted in a single line when finished. Using the opening and terminating comment syntax (/* */) will work for comments.

     

    .

    • gwolfe's avatar
      gwolfe
      ETL

      Thanks JeremyFriedel , although it's not the answer I was looking for, you did answer my question. We are looking to add comments as new lines. Some of our blox widgets can have hundreds of lines of code. We will go with the text editor approach. 

  • Hi gwolfe,

    Thank you for your question.

    Are you referring to the template editor specific to Blox and not the script editor, which is the same for all widgets?

    The template on reload will show the last valid Blox template that didn’t return an invalid template error when saving. If the Blox template has an error all unsaved changes are lost, so it is a good idea to click accept often to limit the potential for this type of loss of progress.

  • Thanks DRay  I am talking about the editor specific to Blox. I understand that it shows the last valid template. The question is how do I add comments? They look to be valid, but disappear after saving.