Results 1 to 3 of 3

Thread: Update timefield values with current time

  1. #1
    Sencha User
    Join Date
    Dec 2012
    Posts
    5
    Vote Rating
    0
      0  

    Default Update timefield values with current time

    Hi All,

    I have a timefield which I want the minValue to be populated with the current time. (so the user cannot schedule a time in the past)

    {
    xtype: 'timefield',
    id: 'id16_scheduleTimeField',
    name: 'scheduleTimeField',
    fieldLabel: 'Time',
    increment: 15,
    format: 'G:i',
    allowBlank: false,
    minValue: Globals.getHours()
    invalidCls:null,
    },

    where

    Globals.getHours = function (){
    var currentTime = new Date();
    var hours = currentTime.getHours().toString();
    var min = currentTime.getMinutes().toString();
    var time = " ";
    if(min <= 9){
    time = hours + ":" + "0" + min;
    }
    else {
    var time = hours + ":" + min;
    }
    return time;
    };

    However, if I dont refresh the browser then the minValue will still show a time in the past. Is there a way to automatically update the timefield to show only current time or update every 15 minutes?

    Thanks,
    Rich

  2. #2
    Sencha User
    Join Date
    Jun 2013
    Posts
    20
    Answers
    1
    Vote Rating
    2
      0  

    Default

    you can write a function in listner and set interval to time to time and set the value to the field.
    from task manager you can call time to time.
    Code:
    Ext.TaskManager.start({			run: this.refreshFieldMethod,
    			interval: 1000
    		});

  3. #3
    Sencha User slemmon's Avatar
    Join Date
    Mar 2009
    Location
    Boise, ID
    Posts
    6,165
    Answers
    505
    Vote Rating
    255
      0  

    Default

    The suggestion from @asankaub seems good for updating your field periodically.
    You might also consider setting a validator on the field (or doing a validation once the form is submitted).
    http://docs.sencha.com/extjs/4.2.1/#...-cfg-validator

Posting Permissions

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