ericjgagnon / wickedpicker

A simple jQuery timepicker
http://ericjgagnon.github.io/wickedpicker/
MIT License
93 stars 78 forks source link

Reset wickedpicker on click #22

Closed c2xbrhdj6u4qs15 closed 8 years ago

c2xbrhdj6u4qs15 commented 8 years ago

Hi,

I am wondering if it is possible to reset or reload the plugin "wickedpicker" on click. I've got a table with rows and each row has it's edit button, so if User clicks the Edit Button a Modal opens and the time in the input field should be predefined, if the User clicks on the input field the exact time should be displayed in the wickedpicker. However this should be individual depending on the time for each row. I got it working if I reload the page every time which is not preferred. So it works the first time after a page reload, but then it always uses the time in the wickedpicker of the initial used time. Example: $('.timepicker').wickedpicker({ now: '21:35', twentyFour: true }); is the initial call, but then if I call the same with a different time I still get the initial time which is "21:35". How can this be reseted or the plugin releaded without a page reload. Thanks

ericjgagnon commented 8 years ago

Hi, I'm not sure if I entirely understand the problem but here goes. It sounds like you want to set the time for each row of your table that has its own instance of a wickerpicker, but shares the same selector (ie .timepicker) ? If that's the case I'd pass the time from the row currently being edited to wickedpicker's init settings.

$('.row-button').on('click', function(event) {
        //Maybe store it as a data attribute on the button or row?
         var rowTime = $(this).data('row-time');
         var wickedpickerOptions = {//whatever options you'd like};
         //check if row time is defined
         if (rowTime) { 
             wickedpickerOptions.now = rowTime;
         }
         // if rowTime isn't defined the wickedpicker will default to now
        $('.timepicker').wickedpicker(wickedpickerOptions);
});

I hope that helps 😄