form.html 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <!DOCTYPE html>
  2. {% load static %}
  3. <html>
  4. <head>
  5. {#<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">#}
  6. <script type="text/javascript">
  7. window.onerror = function (msg) {
  8. document.getElementById('body').setAttribute('JSError', msg)
  9. }
  10. </script>
  11. {{ form.media.css }}
  12. </head>
  13. <body id="body">
  14. <form method="post">
  15. {% csrf_token %}
  16. {{ form }}
  17. <input type="submit" name="save" value="Save"/>
  18. <button type="submit" name="save_continue" value="continue_value">Save &amp; continue</button>
  19. <div class="progress">
  20. <div class="progress-bar" role="progressbar" style="width: 0%;" aria-valuenow="0" aria-valuemin="0"
  21. aria-valuemax="100">0%
  22. </div>
  23. </div>
  24. </form>
  25. {{ form.media.js }}
  26. <script>
  27. (function () {
  28. var form = document.getElementsByTagName('form')[0]
  29. var progressBar = document.getElementsByClassName('progress-bar')[0]
  30. var input = document.createElement('input')
  31. input.type = 'hidden'
  32. input.name = 'progress'
  33. form.appendChild(input)
  34. form.addEventListener('progress', function (event) {
  35. // event.detail.progress is a value between 0 and 1
  36. var percent = Math.round(event.detail.progress * 100)
  37. progressBar.setAttribute('style', 'width:' + percent + '%')
  38. progressBar.setAttribute('aria-valuenow', percent)
  39. progressBar.innerText = percent + '%'
  40. input.value = event.detail.progress
  41. })
  42. })()
  43. </script>
  44. </body>