Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make materialize labels move out of input box when input box is filled via javascript

Normally, with Materialize, the labels for text input boxes show up inside the input boxes until a user enter selects the box and enters text in it. However, when a box's value is filled via javascript, the label does not move out of the way. It stays in the box and overlaps with the text entered. Is there a way to trigger the label transition with javascript as well, so this doesn't happen?

like image 789
neurodynamic Avatar asked Aug 19 '15 16:08

neurodynamic


1 Answers

More specifically, if you are using Materialize in Rails with turbolinks enabled, you will find that Materialize form fields which are prefilled with non-empty values are not active on page load.

The following method worked for me:

$(function() {
    M.updateTextFields();
});

It will add class 'active' to both corresponding labels and prefix icons.

like image 189
elquimista Avatar answered Oct 18 '22 15:10

elquimista