javascript - Converting Bootstrap 3 remote modal to Bootstrap 4 modal with parameters -


so in near future shop going upgrade bootstrap 4 cannot until solve issue using remote modals. here example of how load our modals. reason use remote modals because modal-body dynamic , may use different file based on url. have heard using jquery("#newsmodal").on("load",..) alternative how this? found this not sure how anchor , how build url load remote data.

global php include file:

   <div id="newsmodal" class="modal fade" tabindex="-1" role="dialog" data- ajaxload="true" aria-labelledby="newslabel" aria-hidden="true">         <div class="modal-dialog">             <div class="modal-content">                 <div class="modal-header">                     <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>                     <h3 class="newslabel"></h3>                 </div>                 <div class="noscroll-modal-body">                         <div class="loading">                             <span class="caption">loading...</span>                            <img src="/images/loading.gif" alt="loading">                     </div>                 </div>                 <div class="modal-footer caption">                     <button class="btn btn-right default modal-close" data-dismiss="modal">close</button>                 </div>             </div>         </div>     </div> 

modal_news.php file:

     <form id="newsform">         <div id="hth_err_msg" class="alert alert-danger display-hide col-lg-12 col-md-12 col-sm-12 col-xs-12">                 have errors. please check below.         </div>         <div id="hth_ok_msg" class="alert alert-success display-hide col-lg-12 col-md-12 col-sm-12 col-xs-12">            &#10004;&nbsp;ready          </div>                                  <!-- details //-->         </form> 

here how trigger modals :

   <a href="#newsmodal" id="modal_sbmt" data-toggle="modal" data-target="#newsmodal"      onclick="remote='modal_news.php?user=yardpenalty&pkey=54&function=*general'; remote_target='#newsmodal .noscroll-modal-body'">     <span class="label label-icon label-info">        <i class="fa fa-bullhorn"></i>     </span>     promotional ordering    </a> 

i think need when building anchor dynamically:

a) replace paramters data-attrs

b) use event invoker data-attrs using event.target.id

you might find easier use bootbox.js, can used dynamically create bootstrap modals.

given you've shown, work like:

<a href="/path/to/your/service" class="show-modal">trigger modal</a> 

with

$(function(){      $('.show-modal').on('click', function(e){          e.preventdefault();          var url = $(this).attr('href');          $.get(url)             .done(function(response, status, jqxhr) {                  bootbox.dialog({                     title: 'your title here',                     message: response                 });             });      });  }); 

this assumes response html fragment.

bootbox hasn't officially been confirmed work bootstrap 4, haven't run problems yet (modals seem 1 of few components don't have updated markup in bs4).

disclaimer: contributor bootbox (mainly updating documentation , triaging issues).

if must use bootstrap modal, you're after load(). like:

$(function(){      $('.show-modal').on('click', function(e){          e.preventdefault();          var url = $(this).attr('href');         var dialog = $('#newsmodal').clone();          dialog.load(url, function(){             dialog.modal('show');         });      });  }); 

Comments

Popular posts from this blog

php - How to display all orders for a single product showing the most recent first? Woocommerce -

asp.net - How to correctly use QUERY_STRING in ISAPI rewrite? -

angularjs - How restrict admin panel using in backend laravel and admin panel on angular? -