0

What is the proper way to focus a material design lite TextField?

This works:

$("#myTextField").focus();

This does not work:

document.getElementById('myTextField').parentNode.MaterialTextfield.focus();

However, this very similar code works to disable a TextField:

document.getElementById('myTextField').parentNode.MaterialTextfield.disable();
Lambert
  • 2,233
  • 5
  • 29
  • 44

1 Answers1

3

You don't need jQuery.

  input.focus();
  input.parentNode.classList.add('is-dirty');
Ronnie Royston
  • 16,778
  • 6
  • 77
  • 91
  • 1
    is-dirty will permanently float the label - use "is-focused" instead to just float it whilst the input has focus. – fubaar Feb 20 '18 at 11:34