generic-github-user / Star

A website where anyone can rate anything.
0 stars 1 forks source link

Clear new post settings after creating post #17

Closed generic-github-user closed 6 years ago

generic-github-user commented 6 years ago

Post settings text fields are cleared when the new post settings panel is opened.

image

When the value is set to blank by JavaScript, the text field are not automatically marked as such by removing the is-dirty class. This class must be artificially removed:

const new_post = function () {
      var title = document.querySelector("#new-post-title-input");
      title.value = "";
      title.parentNode.classList.remove("is-dirty");
      var note = document.querySelector("#new-post-note-input");
      note.value = "";
      note.parentNode.classList.remove("is-dirty");

      document.querySelector("#new-post-panel").className = "visible";
}

Note: Post settings cannot be set to "", because MDL still detects that the input field contains text, so the text field title is displayed above the field.

Also tested:

generic-github-user commented 6 years ago

Apparently this is a bug in MDL:

See @gustalima's comment for the solution I used: https://github.com/google/material-design-lite/issues/1287#issuecomment-128475300