Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Regular Coder Jesper Møller's Avatar
    Join Date
    Jun 2006
    Location
    Denmark, Copenhagen
    Posts
    138
    Thanks
    9
    Thanked 0 Times in 0 Posts

    Cant set options in Jquery scripts with vars

    I have found a script i like to use (but needs to tweek it a little)
    DateTimePicker jQuery plugin - XDSoft

    In the script ther is a option list:
    Code:
    $('#datetimepicker_').datetimepicker({
    		minDate:0,
    		lang:'da',
    		step:15,
    		mask:'9999/19/39 29:55',
    		yearStart: '2014',
    		minTime:'8:00',
    		maxTime:'15:50',
    		onGenerate:function( ct ){
    		$(this).find('.xdsoft_date.xdsoft_weekend')
    			.addClass('xdsoft_disabled');
    				onChangeDateTime:logic,
    				onShow:logic,
    		},
    		weekends:['27.03.2014','24.12.2014'],
    		});
    What i want to do (try to do) is to set the options with var's so the work dynamecly depending on actual time/date
    Like:
    Code:
    var time = dt.getHours()+1;
    var minut = dt.getMinutes();
    var newtime = time + ":" + minut;
    this.setOptions({
    	minTime:newtime,
    	maxTime:'15:50',
    });
    However no matter what i try i cant set the minTime or maxTime (or other options) using var's
    what am i doing wrong / how can i get this to work
    "True knowledge exists in knowing that you know nothing."

    "Education is learning what you didn't even know you didn't know!"

  • #2
    The fat guy next door VIPStephan's Avatar
    Join Date
    Jan 2006
    Location
    Halle (Saale), Germany
    Posts
    8,927
    Thanks
    6
    Thanked 1,041 Times in 1,014 Posts
    What does the error console say?

    Where are you setting this, actually? Where is “dt” defined? To which object refers “this” in your code there?
    It would probably help to see all of your JS.

  • #3
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,075
    Thanks
    0
    Thanked 256 Times in 252 Posts
    Code:
    var dt = new Date();
    var time = dt.getHours()+1;
    var minut = dt.getMinutes();
    var newtime = time + ":" + minut;
    $('#datetimepicker_').datetimepicker({
        minTime: newtime,
        maxTime: '15:50',
        ...and so on
    });
    Or if you want to change the minTime after the datepicker is initialized:
    Code:
    //initialize datepicker
    var $datepicker = $('#datetimepicker_').datetimepicker({
         minTime:'8:00',
         ...
    });
    
    //then later on...
    var dt = new Date();
    var time = dt.getHours()+1;
    var minut = dt.getMinutes();
    var newtime = time + ":" + minut;
    $datepicker.setOptions({
        minTime: newtime,
        maxTime: '15:50',
        ...
    });
    I'm not sure if that's the right way to set datepicker options dynamically because I don't know which datepicker plugin you are using, but I think that you should set one option at a time like this?
    Code:
    $datepicker.setOptions('minTime', newtime);
    Last edited by glenngv; 03-22-2014 at 10:49 PM.
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________

  • Users who have thanked glenngv for this post:

    Jesper Møller (03-23-2014)

  • #4
    Regular Coder Jesper Møller's Avatar
    Join Date
    Jun 2006
    Location
    Denmark, Copenhagen
    Posts
    138
    Thanks
    9
    Thanked 0 Times in 0 Posts

    Thumbs up

    Quote Originally Posted by glenngv View Post
    Code:
    var dt = new Date();
    var time = dt.getHours()+1;
    var minut = dt.getMinutes();
    var newtime = time + ":" + minut;
    $('#datetimepicker_').datetimepicker({
        minTime: newtime,
        maxTime: '15:50',
        ...and so on
    });
    Or if you want to change the minTime after the datepicker is initialized:
    Code:
    //initialize datepicker
    var $datepicker = $('#datetimepicker_').datetimepicker({
         minTime:'8:00',
         ...
    });
    
    //then later on...
    var dt = new Date();
    var time = dt.getHours()+1;
    var minut = dt.getMinutes();
    var newtime = time + ":" + minut;
    $datepicker.setOptions({
        minTime: newtime,
        maxTime: '15:50',
        ...
    });
    I'm not sure if that's the right way to set datepicker options dynamically because I don't know which datepicker plugin you are using, but I think that you should set one option at a time like this?
    Code:
    $datepicker.setOptions('minTime', newtime);
    Thanks that did it
    very simula to what i tryde (dont know why my try dint workd)
    "True knowledge exists in knowing that you know nothing."

    "Education is learning what you didn't even know you didn't know!"


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •