Jump to content

Call Timepicker with data-values


ztimer
Go to solution Solved by cyberRobot,

Recommended Posts

I have trouble calling timepicker with class and passing data-values to the script.

So what i have so far is one loop that for each entry it will create
 

foreach($data as $value){
$min_hour = $value['minhour']; // returns value from DB like 7 to 12
echo '<td><input type="text" value="" class="schedule-timepicker" data-minhour="'.$min_hour.'" data-minminutes="30" data-maxhour="17" data-maxminutes="00"></td>';
}

Then in js file I have

$(document).ready(function(){

    $('.schedule-timepicker').timepicker({
        timeFormat: 'HH:mm:ss',
        minDate: new Date(1, 1, 1, $('.schedule-timepicker').data('minhour'), 00),
        maxDate: new Date(1, 1, 1, $('.schedule-timepicker').data('maxhour'), 00),
    });
});

Problem is that the timepicker is called out and works but every input has the same minimum hours value as the first one. Please help how to resolve this. Thanks.

 

Link to comment
Share on other sites

  • Solution

Were you able to adapt the code to work with the timepicker plugin? Perhaps something like the following will work:

$(document).ready(function(){
    $('.schedule-timepicker').each(function() {
 
 
        $(this).timepicker({
            timeFormat: 'HH:mm:ss',
            minDate: new Date(1, 1, 1, $(this).data('minhour'), 00),
            maxDate: new Date(1, 1, 1, $(this).data('maxhour'), 00),
        });
 
 
    });
});

Note that the timepicker code is untested.

  • Like 1
Link to comment
Share on other sites

Wow. It worked out of box. Thanks. I did not realize to use "this" and not to call it again ..
Lesson learned. First use class and then use this

You can't believe how happy this made me. I can continue now with the code. 

Thanks for this..

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.