Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't get driver to execute from a button click #221

Closed
lavafactory opened this issue Feb 19, 2020 · 3 comments
Closed

Can't get driver to execute from a button click #221

lavafactory opened this issue Feb 19, 2020 · 3 comments

Comments

@lavafactory
Copy link

lavafactory commented Feb 19, 2020

I'm sure I'm doing something wrong here. Driver seems to work fine if it's included inline in a page. For example

const driver = new Driver();

  driver.highlight({
  element: '#title',
  popover: {
    title: 'Title for the Popover',
    description: 'Description for it',
    }
  });

However if I wrap it in a function and try to call it from a click like this, it fails:

function startTutorial()
{
  const driver = new Driver();

  driver.highlight({
  element: '#title',
  popover: {
    title: 'Title for the Popover',
    description: 'Description for it',
    }
  });
}

Essentially the screen dims like it's going to popover, then goes back to normal without showing the pop.

@kamranahmedse
Copy link
Owner

You need to add e.stopPropagation() on the button click that triggers the driver.

@lavafactory
Copy link
Author

lavafactory commented Feb 19, 2020

Thank you for this. I saw that line all the way at the end of the doc

Note – Do not forget to add e.stopPropagation() to the click binding that triggers driver

But I'm no expert in javascript, and this wasn't obvious to me. Here's an example I used, and it may be helpful for others in the future:

Button:
<a class="btn btn-success" href="javascript:void(0);" id="tutorial">Tutorial</a>

Event Code

document.querySelector("#tutorial").addEventListener('click',
  function(e){
    const driver = new Driver();

    driver.highlight({
    element: '#title',
    popover: {
      title: 'Title for the Popover',
      description: 'Description for it',
      }
    });
    e.stopPropagation();
    
  })

Hope this helps someone else.

@kamranahmedse
Copy link
Owner

@lavafactory you need to put e.stopPropagation() at the top of the event body

document.querySelector("#tutorial").addEventListener('click', function(e){
    e.stopPropagation();

    const driver = new Driver();

    driver.highlight({
        element: '#title',
        popover: {
          title: 'Title for the Popover',
          description: 'Description for it',
        }
     });    
  })

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants