mkhairi / materialize-sass

Materializecss rubygem for Rails Asset Pipeline / Sprockets
http://materialize.labs.my/
MIT License
805 stars 243 forks source link

Can't initialize materialize js components #114

Closed gudata closed 7 years ago

gudata commented 8 years ago

Once there was solution with which was possible to configure the js components.

var formElementsInit = function() {
  // field validations
  $("input:file.validation--failed").parents('input-field').find("input:text.file-path").first().addClass('validation--failed invalid');

  // update labels if there's content
  Materialize.updateTextFields();

  $(".button-collapse").sideNav();
  $('.parallax').parallax();
  $('select').material_select();
  $(".dropdown-button").dropdown({inDuration: 300,
    outDuration: 225,
    constrain_width: false,
    hover: false,
    gutter: 0,
    belowOrigin: true,
    alignment: 'right'
  });
  $('.datepicker').pickadate({
    selectMonths: true, // Creates a dropdown to control month
    selectYears: 100 // Creates a dropdown of 100 years to control year
  });

  $('ul.tabs').tabs();
};

$(document).ready(formElementsInit) //standard jQuery behavior
$(document).on('page:load', formElementsInit) //adaptation to turbolinks

but it is not working any more. I saw integration with turbolinks on this commit

https://github.com/mkhairi/materialize-sass/commit/bd3fb740389730a2e15513232c395948face7164

but I can't find a way to initialize the components. please help.

rubendinho commented 8 years ago

I think you still need to wrap the materialize components inside $( document ).ready(function(){

gudata commented 7 years ago

The initialization is in document.ready function.

Can you give example how you initialize the materilize js components with the new version of this gem?