-2

After a user presses the send button, I want the send button to be disabled for 10 seconds. After the 10 seconds have elapsed, the button should be enabled again.

The setTimeout(resetMaterialTextfield(messageInputElement), 10000); function doesn't seem to work below.

function onMessageFormSubmit(e) {
  e.preventDefault();

  // Check that the user entered a message that is a number between 1 and 100 and is signed in.
  if (messageInputElement.value && checkSignedInWithMessage()) {
    if (isNaN(messageInputElement.value)){
      window.alert(" Please enter a number between 1 - 100 (inclusive) ");
    }
    else {
      if (messageInputElement.value <= 0 || messageInputElement.value > 100){
        window.alert(" Please enter a number between 1 - 100 (inclusive) ");
      }
      else {
        saveMessage(messageInputElement.value).then(function () {
          // Clear message text field and re-enable the SEND button.
          setTimeout(resetMaterialTextfield(messageInputElement), 1000);
          toggleButton();
        });
      }
    }
  }
}

And here is the other function:

function toggleButton() {
  if (messageInputElement.value) {
    submitButtonElement.removeAttribute('disabled');
  } else {
    submitButtonElement.setAttribute('disabled', 'true');
  }
}

Grateful for any help please.

Thank you!

Has
  • 885
  • 4
  • 13
  • 31

1 Answers1

-1

Try setTimeout(resetMaterialTextfield.bind(null, messageInputElement), 1000);

Kaelan Mikowicz
  • 345
  • 2
  • 12
  • Thank you. I think it is the toggleButton that I need to time out for 10 seconds. I tried setTimeout(toggleButton(null), 10000); and that doesn't work. – Has Apr 04 '20 at 00:39