Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bootstrap material floating label not working on autofill

I am using bootstrap material kit on my page, but I have a problem with a label not going up on autofill in chrome. I have searched around and saw that is a known issue, and have tried with using the solution suggested here. But it is still not working for me. Don't know how to fix it?

This is how I call my stylesheets:

<link href="/css/material-kit/css/bootstrap.min.css" rel="stylesheet" />
<link href="/css/material-kit/css/material-kit.css" rel="stylesheet"/>
<link href="/css/landing-page.css" rel="stylesheet"/>

Html:

<div class="form-group label-floating">
    <label class="control-label">Password</label>
    <input type="password" name="password" class="form-control" required/>
    @if ($errors->has('password'))
        <span class="help-block">
            <strong>{{ $errors->first('password') }}</strong>
        </span>
    @endif
</div>

And scripts:

<!--   Core JS Files   -->
<script src="/js/landing-page/jquery.min.js" type="text/javascript"></script>
<script src="/js/landing-page/bootstrap.min.js" type="text/javascript"></script>
<script src="/js/landing-page/material.min.js"></script>
<script>
    $(document).ready(function() {
            $.material.options.autofill = true;
            $.material.init();
    });
</script>
like image 995
Ludwig Avatar asked Feb 05 '17 18:02

Ludwig


1 Answers

This is what worked for me in the end:

$(window).load($.debounce(200,function(){
    $('input:-webkit-autofill').each(function(){
        if ($(this).val().length !== "") {
            $(this).siblings('label, i').addClass('active');
        }
    });
}));
like image 69
Ludwig Avatar answered Oct 19 '22 15:10

Ludwig