edit_item.html 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. {% extends "base.html" %}
  2. {% block title %}
  3. {{ item.name }}
  4. {% endblock %}
  5. {% block content %}
  6. <main>
  7. <!-- bread crumb -->
  8. <nav aria-label="breadcrumb">
  9. <ol class="breadcrumb">
  10. <li class="breadcrumb-item"><a href="/">Home</a></li>
  11. <li class="breadcrumb-item"><a href="/{{ type }}">{{ type|name_by_type }}</a></li>
  12. <li class="breadcrumb-item active" aria-current="page">{{ item.name }}</li>
  13. </ol>
  14. </nav>
  15. <!-- flash messages -->
  16. {% with messages = get_flashed_messages(with_categories=true) %}
  17. {% for category, msg in messages %}
  18. <div class="alert alert-{{ category }} alert-dismissible fade show" role="alert">
  19. {{ msg }}
  20. <button type="button" class="close" data-dismiss="alert" aria-label="Close">
  21. <span aria-hidden="true">&times;</span>
  22. </button>
  23. </div>
  24. {% endfor %}
  25. {% endwith %}
  26. <div class="container mt-5">
  27. <div class="border-bottom pt-3">
  28. <h1 >Edit '{{ item.name }}'</h1>
  29. </div>
  30. <form class="pr-5" method="post" onsubmit="get_chips()" action="/{{ type }}/{{ item.id }}/edit">
  31. {{ form.hidden_tag() }}
  32. {% for field in form %}
  33. {% if field.name != "csrf_token" %}
  34. <!-- show errors -->
  35. {% for error in field.errors %}
  36. <p class="text-danger">{{ error }}</p>
  37. {% endfor %}
  38. {% if field.name == 'value' %}
  39. <div class="input-group mt-3">
  40. <div class="input-group-prepend w-60 ml-0">
  41. {{ form.value.label(class="input-group-text w-80") }}
  42. {{ form.comparision.label(class="input-group-text w-40") }}
  43. </div>
  44. <div class="input-group-append w-40">
  45. {{ form.value2.label(class="input-group-text w-100") }}
  46. </div>
  47. </div>
  48. <div class="input-group mb-3">
  49. <div class="input-group w-40">
  50. {{ form.value(class="form-control w-50", value=form.value.data) }}
  51. </div>
  52. <div class="input-group w-20">
  53. {{ form.comparision(class="form-control", value=form.comparision.data) }}
  54. </div>
  55. <div class="input-group w-40">
  56. {{ form.value2(class="form-control", value=form.value2.data) }}
  57. </div>
  58. </div>
  59. {% elif field.name != 'comparision' and field.name != 'value2' %}
  60. <div class="input-group my-3">
  61. <div class="input-group-prepend">
  62. {{ field.label(class="input-group-text fixed-label") }}
  63. </div>
  64. {% if field.data is iterable and field.data is not string %}
  65. <!-- choices for chips -->
  66. <input type="text" class="form-control" list="{{ field.name }}Opt" data-name="{{ field.name }}"
  67. onkeyup="filter_options(this)" oninput="add_chip(this, '{{ field.name }}')">
  68. <datalist id="{{ field.name }}Opt">
  69. {% for option in field.choices %}
  70. <option {% if option.0 in field.data %}disabled{% endif %}>
  71. {{ option.1 }}
  72. </option>
  73. {% endfor %}
  74. </datalist>
  75. <!--
  76. <select class="form-control multyselect" id="{{ field.name }}" name="{{ field.name }}"
  77. onchange="add_chip(this, '{{ field.name }}')">
  78. <option value="0" select="">&lt; Select &gt;</option>
  79. {% for option in field.choices %}
  80. <option value="{{ option.0 }}" {% if option.0 in field.data %}disabled{% endif %}>
  81. {{ option.1 }}
  82. </option>
  83. {% endfor %}
  84. </select>
  85. -->
  86. {% else %}
  87. <!-- other fields -->
  88. {{ field(class="form-control", value=field.data) }}
  89. {% endif %}
  90. </div>
  91. <!-- chips -->
  92. {% if field.data is iterable and field.data is not string %}
  93. <!-- multi-select -->
  94. <select class="d-none" id="{{ field.name }}" name="{{ field.name }}" multiple>
  95. {% for option in field.choices %}
  96. <option value="{{ option.0 }}">
  97. {{ option.1 }}
  98. </option>
  99. {% endfor %}
  100. </select>
  101. <!-- chips -->
  102. <div id="chips_{{ field.name }}">
  103. {% for option in field.choices if option.0 in field.data %}
  104. <div class="chip mr-1" data-id="{{ option.0|int - 1 }}">
  105. <small>{{ option.1 }}</small>
  106. <span class="closebtn" onclick="delete_chip(this.parentElement, '{{ field.name }}')">&times;</span>
  107. </div>
  108. {% endfor %}
  109. </div>
  110. {% endif %}
  111. {% endif %}
  112. {% endif %}
  113. {% endfor %}
  114. <p>
  115. <button class="btn btn-primary px-5 my-3" type="submit">Save</button>
  116. </p>
  117. </form>
  118. </div>
  119. </main>
  120. {% endblock %}