How can I prevent the timer from auto starting?
I would like the time value to be empty by default but the field would be required forcing people to submit a value.

Comments

jeremy’s picture

Category: task » feature

It's not currently possible, marking as a feature request.

NToronto’s picture

Thank you Jeremy.

NToronto’s picture

Hi Jeremy,

Until this feature can be added as an admin configuration option, can you advise on a temporary solution to prevent the timer from auto-starting?

Thanks

NToronto’s picture

Temporary hack until an admin option is available, but this worked for me:

In support_timer.js I commented out line 15:

timer();

In support_timer.module, I commented out the following fields:

    $form['timer']['pause'] = array(
      '#type' => $visible ? 'submit' : 'hidden',
      '#value' => t('Pause'),
      '#prefix' => '  ',
      '#attributes' => array('onclick' => 'pause_timer(); return false;'),
    );
    $form['timer']['reset'] = array(
      '#type' => $visible ? 'submit' : 'hidden',
      '#value' => t('Reset'),
      '#attributes' => array('onclick' => 'reset_timer(); return false;'),
nubeli’s picture

I found a much simpler way to have the timer only start when pressing the button. At the top of the support_timer.js switch the states for the "enabled" and "delayed" variables, such that:

var enabled = 0;
var delayed = 1;

And that's it!

But now it seems like you have to press the Pause button to have it start. It works but it's not really user-friendly. So I made the button text change when clicked. First, in support_timer.module change line 218 to '#value' => t('Start'), such that it looks like this:

    $form['timer']['pause'] = array(
      '#type' => $visible ? 'submit' : 'hidden',
      '#value' => t('Pause'),
      '#prefix' => '  ',
      '#attributes' => array('onclick' => 'pause_timer(); return false;'),
    );

And then I inserted a bit of jquery so that the text changes to Pause when clicking the Start button. Starting at line 31 change from:

function pause_timer() {
  if (enabled) {
    enabled = 0;
    window.setTimeout(function() {
      delay();
    }, 1000);
  }
  else {
    if (delayed) {
      enabled = 1;
      delayed = 0;
      timer();
    }
  }
}

to:

function pause_timer() {
  if (enabled) {
    enabled = 0;
    window.setTimeout(function() {
      delay();
    }, 1000);
    // replace "Pause" with "Start"
    $("#edit-pause")[0].value = "Start";
  }
  else {
    if (delayed) {
      enabled = 1;
      delayed = 0;
      timer();
      // replace "Start with "Pause"
      $("#edit-pause")[0].value = "Pause";
    }
  }
}

I think it reverses the logic of the function but it works as advertised so far for me.