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 494 forks source link

how to use click function in vex.dialog.open? #239

Closed xiranst closed 6 years ago

xiranst commented 7 years ago

i used vex.dialog.open a html page, how to click some elements in the same windows and then close it?

bbatliner commented 7 years ago

I'm not sure what you mean. Do you mean putting an iframe inside of the dialog? Do you mean putting an HTML partial or view inside of the dialog and then closing the dialog programmatically?

xiranst commented 7 years ago

@bbatliner thanks for you reply. not iframe. i have solve my question. i want to add click or other event into the open window. i added the click event code in afterOpen function and can work for me. do you have another method to do it?

bbatliner commented 7 years ago

If you want to add a click event to the vex dialog itself, then this has to be done in afterOpen, as you've done, because the elements don't exist until after the call to open.

If you want to add events to your content that you are showing in the dialog, you can do this before opening the dialog.

Here's an example:

var myContent = document.createElement('div')
var myButton = document.createElement('button')
myButton.textContent = 'Click me'
myButton.addEventListener('click', (e) => {
    e.preventDefault()
    console.log('clicked')
})
myContent.appendChild(myButton)

vex.dialog.open({ unsafeMessage: myContent })
xiranst commented 7 years ago

@bbatliner thanks for your reply. i will try it later. could you check my another issue? https://github.com/HubSpot/vex/issues/240 . in the vex open, i have init the tinymce and it is working, but the textarea can not get the data of tinymce. so the form is not submitted.