Guest User

Untitled

a guest
Dec 9th, 2019
114
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <script>
  2. $(document).ready(function(){
  3. $("#add-item").click(function(ev) {
  4. ev.preventDefault();
  5. var count = $('#order').children().length;
  6. var tmplMarkup = $("#item-order").html();
  7. var compiledTmpl = tmplMarkup.replace(/__prefix__/g, count);
  8. $("div#order").append(compiledTmpl);
  9.  
  10. // update form count
  11. $('#id_product-TOTAL_FORMS').attr('value', count + 1);
  12.  
  13. // some animate to scroll to view our new form
  14. $('html, body').animate({
  15. scrollTop: $("#add-item").position().top-200
  16. }, 800);
  17. });
  18. });
  19. </script>
  20.  
  21.  
  22. HTML-----------------
  23. <div id="order" class="pure-form pure-form-aligned">
  24. {% for item_order_form in formset %}
  25. <div id="item-{{ forloop.counter0 }}" class="pure-control-group">
  26. {{ item_order_form.as_p }}
  27. </div>
  28. {% endfor %}
  29. </div>
  30.  
  31. <div class="pure-control-group" >
  32. <a class="btn btn-light" id="add-item"><i class="fa fa-plus"></i> Add Item</a>
  33. <button class="btn btn-primary pull-right" value="Save"><i class="fa fa-floppy-o"></i> Salvar</button>
  34. </div>
  35. </form>
  36. </div>
  37.  
  38. <script type="text/html" id="item-order">
  39. <div id="item-__prefix__" style="margin-top: 10px" class="pure-control-group">
  40. {{ formset.empty_form.as_p }}
  41. </div>
  42. </script>
RAW Paste Data