mkhairi / materialize-sass

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

Rails dynamic dropdown not updating #118

Closed reckerswartz closed 6 years ago

reckerswartz commented 7 years ago

I using materialize-sass gem in my rails application. In my application I need to alter the second drop-down menu on based of first drop-down selected options.

My JS var branch = $('#user_branch_id').html(); $('#user_course_id').change(function(){ var selectedCourseCategory = $('#user_course_id :selected').text(); var optgroup = "optgroup[label="+ selectedCourseCategory + "]"; var branchOptions = $(branch).filter(optgroup).html(); console.log(branchOptions); if (branchOptions) { $('#user_branch_id').html(branchOptions);

  $('#user_branch_id').trigger('contentChanged');

  $('select').on('contentChanged', function() {
          // re-initialize (update)
        $(this).material_select();
    });

}

}); }

HTML------------------------------------------------------------------------------------

<%= f.collection_select :course_id, Course.order(:name), :id, :name, include_blank: 'Select an Course...' %>
```
<%= f.grouped_collection_select :branch_id, Course.order(:name), :branches, :name, :id, :name, include_blank: 'Select an Branch...' %>
``` ##

Its changing the elements when inspected using developer tools but it seems that materialize-sass creating another dropdown to display

--------------------------------------------------------below it which is altered using java script--------

How can i create dynamic drop-down and also show the chances in real time.

For reference you can look into the file @ https://ide.c9.io/reckerswartz/mgr

mkhairi commented 6 years ago

try check with latest release of materializecss. closing old issue.