wakirin / Litepicker

Date range picker - lightweight, no dependencies
MIT License
899 stars 132 forks source link

litepicker.com/docs/events - where do I put those lines of code? #301

Open ghost opened 2 years ago

ghost commented 2 years ago

I tried to put

      setup: (picker) => {
        picker.on('before:click', (target) => {
          window.alert(1);
        });
      }

into Picker options.

var picker_options = {
  element: _start_element[0],
  elementEnd: _end_element[0],
  format: "YYYY-MM-DD",
  singleMode: false

  setup: (picker) => {
    picker.on('before:click', (target) => {
      window.alert(1);
    });
  }
}
var p = new Litepicker(picker_options);

It doesn't work. Where do I put this? Can examples be more detailed, maybe the full snippet for applying the litepicker to an input?

rbosch commented 2 years ago

You bind them to the instance of the initialisation code. I guess you figured it out by now, but this is for others.

var picker_options = {
  element: _start_element[0],
  elementEnd: _end_element[0],
  format: "YYYY-MM-DD",
  singleMode: false

  setup: (picker) => {
    picker.on('before:click', (target) => {
      window.alert(1);
    });
  }
}

var p = new Litepicker(picker_options);
p.on('show', () => {
        // some action after show
        alert('hello world'); 
});