HubSpot / vex

A modern dialog library which is highly configurable and easy to style. #hubspot-open-source
http://github.hubspot.com/vex/docs/welcome
MIT License
6.92k stars 491 forks source link

[Question] Am I able to code HTML5 in content and unsafeContent? #224

Closed MaxJeong closed 7 years ago

MaxJeong commented 7 years ago

Basically, I need to write my own html5 code in vex dialog because I need a script tag which prints a list of games into a div class.

I have something like this:

vex.dialog.open({
            overlayClosesOnClick: false,
            content: [
            <script type="text/javascript">
                for (var i = 0; i < games.length; i++) {,
                    var x = document.createElement("label")
                    var y = document.createTextNode(games[i].gamename)
                    x.appendChild(y)
                    document.getElementById("widgetlist").appendChild(x)
                }
            </script>
            <div class="vex-custom-field-wrapper" id="widgetlist">
            </div>
            ].join(''),
            callback: function (value){
                if (value) {
                    return;
                } else {
                    return;
                }
            }.bind(this)
})

The result is I get a vex popup with the content returning [object Object].

I know I can write html5 in input option but I don't think it can read javascript, I've tried it before. Are there other ways to replicate what I did or am I doing something wrong with the content option?

bbatliner commented 7 years ago

Have you tried creating the widgetlist HTML string programmatically before opening the vex dialog, and then passing the string to the unsafeContent option? This seems like the easiest way to accomplish what you're doing.

MaxJeong commented 7 years ago

Is passing the HTML string into unsafeContent the only way? You can't hard code HTML into either content or unsafeContent?

Edit: I found out that in vex dialog, I have to use unsafeMessage instead but I don't think it can read javascript code. A better question would be, which vex dialog option allows me to put javascript code? Like what I tried to do above.