driver.js icon indicating copy to clipboard operation
driver.js copied to clipboard

[Feature request] OnClick callback

Open thomasthiebaud opened this issue 7 years ago • 8 comments

Hi,

is it possible to add some optional callback when one of the button (close, next, previous, done) is called ?

thomasthiebaud avatar Mar 27 '18 11:03 thomasthiebaud

I'd love to see this – ideally with the ability to block even the selection of the next step, so one could (more easily) drive js client apps with async operations creating the elements for the next step.

alappe avatar Mar 28 '18 07:03 alappe

different callback for every time next is called?

moghya avatar Mar 29 '18 15:03 moghya

That would be perfect for some scenarios of mine, yes.

To illustrate with pseudocode:

driver.defineSteps([
  {
    element: '#first-element-introduction',
    popover: {
      title: 'Welcome',
      description: 'we take you on a journey…',
      position: 'left'
    }
  }, {
    element: '#second-element-introduction',
    pre: (next) => {
      // Do some ajax calls, create nodes from results, whatever…
      const n = document.createElement('div');
      n.id = 'second-element-introduction';
      next();
    },
    popover: {
      title: 'Behold',
      description: 'the mighty div in its natural habitat…',
      position: 'right'
    }
  }
]);

As far as I played with the code for now, it seems that the selection of the elements is done on the defineSteps() call, so if an element doesn't exist at this point of time, the step fails later on. For the code above it would be necessary to select the element when the functions callback is called.

My issue could also be solved with the request of @thomasthiebaud if I understand it correctly, leading to something like:

driver.defineSteps([
  {
    element: '#first-element-introduction',
    popover: {
      title: 'Welcome',
      description: 'we take you on a journey…',
      position: 'left'
    },
    onNext: (done) => {
      // Do some ajax calls, create nodes from results, whatever…
      const n = document.createElement('div');
      n.id = 'second-element-introduction';
      done();
    }
  }, {
    element: '#second-element-introduction',
    popover: {
      title: 'Behold',
      description: 'the mighty div in its natural habitat…',
      position: 'left'
    }
  }
]);

alappe avatar Mar 31 '18 09:03 alappe

This would be extremely useful to have! In addition to the previous, next, close and done; would it make sense to also have one for when the user decides to prematurely terminate the driver by clicking away? Possibly return the step that it was on when the termination occurred?

bombsite avatar Apr 05 '18 21:04 bombsite

That would be perfect for some scenarios of mine, yes.

To illustrate with pseudocode:

driver.defineSteps([
  {
    element: '#first-element-introduction',
    popover: {
      title: 'Welcome',
      description: 'we take you on a journey…',
      position: 'left'
    }
  }, {
    element: '#second-element-introduction',
    pre: (next) => {
      // Do some ajax calls, create nodes from results, whatever…
      const n = document.createElement('div');
      n.id = 'second-element-introduction';
      next();
    },
    popover: {
      title: 'Behold',
      description: 'the mighty div in its natural habitat…',
      position: 'right'
    }
  }
]);

As far as I played with the code for now, it seems that the selection of the elements is done on the defineSteps() call, so if an element doesn't exist at this point of time, the step fails later on. For the code above it would be necessary to select the element when the functions callback is called.

My issue could also be solved with the request of @thomasthiebaud if I understand it correctly, leading to something like:

driver.defineSteps([
  {
    element: '#first-element-introduction',
    popover: {
      title: 'Welcome',
      description: 'we take you on a journey…',
      position: 'left'
    },
    onNext: (done) => {
      // Do some ajax calls, create nodes from results, whatever…
      const n = document.createElement('div');
      n.id = 'second-element-introduction';
      done();
    }
  }, {
    element: '#second-element-introduction',
    popover: {
      title: 'Behold',
      description: 'the mighty div in its natural habitat…',
      position: 'left'
    }
  }
]);

Hi, Did you solve? I have same problem

jawn-ha avatar Nov 03 '20 09:11 jawn-ha

@thomasthiebaud

Have you found the solution?

Naren-hybreeder avatar Mar 23 '22 11:03 Naren-hybreeder

No, I used something else. Maybe newer versions support it

thomasthiebaud avatar Mar 24 '22 15:03 thomasthiebaud

@thomasthiebaud Thanks for the response, So many attempts, I have found the solution, My issue was, I have to call one function after clicking on the Done button.

Will share the solution here soon...

Naren-hybreeder avatar Mar 24 '22 18:03 Naren-hybreeder

We just released v1.0 of driver.js which has been rewritten from the ground up. There are more simplified hooks which give you more control over the popover and the whole lifecycle. Please have a look at the docs and do let me know if you face any issues.

kamranahmedse avatar Jul 05 '23 17:07 kamranahmedse