Switch initialization added dynamically to materialization

I have an ajax request that dynamically creates a modal window with radio buttons.

I see in the materialize documentation that you can execute material_select() to get selects , however, correctly, I do not see in the documentation on initializing radio dynamically.

How to initialize dynamically loaded switches?

For reference, here is an example of a modal that I load dynamically:

 <div id="import-modal" class="modal modal-fixed-footer"> <div class="modal-content"> <h4>Import Data</h4> <p> <input name="import-group" type="radio" id="import-modal-csv"/> <label for="import-modal-csv">Csv</label> <div>Import a csv file.</div> <p/> <p> <input name="import-group" type="radio" id="import-modal-excel"/> <label for="import-modal-excel">Excel</label> <div>Import a excel file.</div> </p> </div> <div class="modal-footer"> <a href="#!" class="modal-action modal-close waves-effect waves-green btn-flat ">Import</a> </div> </div> 

change 1

I add the dynamic div above using jquery to the parent container on the click button:

  import_click: function(){ $.ajax({ url: 'template/import.html', success: function (response) { $('#container').append(response); } }); } 
+5
source share
1 answer

Radio buttons do not require javascript initialization. Just make sure that you add them dynamically to give them a new identifier, because if they conflict with existing switches, they will not work.

+4
source

All Articles