Style: Item form

- Add bootstrap layout+css to add/update form
This commit is contained in:
Candifloss 2025-04-04 16:01:13 +05:30
parent 233e8a0cd3
commit 0a87bfd570

View File

@ -5,57 +5,120 @@
<title>{% if item %}Update{% else %}Add{% endif %} Item</title> <title>{% if item %}Update{% else %}Add{% endif %} Item</title>
{% include 'favicon.html' %} {% include 'favicon.html' %}
<link href="{{ url_for('static', filename='css/bootstrap.min.css') }}" rel="stylesheet"> <link href="{{ url_for('static', filename='css/bootstrap.min.css') }}" rel="stylesheet">
<link href="{{ url_for('static', filename='css/bootstrap-icons.min.css') }}" rel="stylesheet">
<style>
.form-container {
max-width: 1000px;
margin: 0 auto;
}
.form-card {
background: white;
border-radius: 0.5rem;
box-shadow: 0 0.5rem 1rem rgba(0, 0, 0, 0.1);
}
.form-field {
margin-bottom: 1.5rem;
}
.sticky-actions {
position: sticky;
bottom: 0;
background: white;
padding: 1rem 0;
border-top: 1px solid #dee2e6;
margin-top: 2rem;
}
.error-message {
color: #dc3545;
margin-bottom: 1.5rem;
padding: 0.75rem;
background-color: #f8d7da;
border-radius: 0.25rem;
}
select.form-control {
appearance: auto; /* Keep native select dropdown arrow */
}
</style>
</head> </head>
<body> <body>
{% include 'header.html' %} {% include 'header.html' %}
<main class="container mt-5 pt-3">
<h2>{% if item %}Update{% else %}Add{% endif %} Item</h2> <main class="container mt-5">
<div class="form-container">
<h2 class="mb-4">{% if item %}Update{% else %}Add{% endif %} Item</h2>
<!-- Display error message if any --> <!-- Display error message if any -->
{% if error %} {% if error %}
<p>{{ error }}</p> <div class="error-message">
{% endif %} {{ error }}
</div>
{% endif %}
<!-- Form for adding/updating an item --> <div class="form-card p-4">
<form method="POST"> <form method="POST">
{% for attrib in item_attributes -%} <div class="row">
<p> {% for attrib in item_attributes -%}
<label for="{{ attrib.attrib_name }}">{{ attrib.display_name }}:</label> <div class="col-md-6">
{%- if attrib.html_input_type == "select" %} <div class="form-field">
<!-- Dropdown for select fields --> <label for="{{ attrib.attrib_name }}" class="form-label fw-bold mb-2">
<select id="{{ attrib.attrib_name }}" name="{{ attrib.attrib_name }}" {{ attrib.display_name }}
{%- if attrib.required -%} required {%- endif -%} {% if attrib.required %}<span class="text-danger">*</span>{% endif %}
> </label>
{% for option in attrib.options -%}
<option value="{{ option }}" {%- if attrib.html_input_type == "select" %}
{%- if attrib.default_val is not none and attrib.default_val == option %} selected {%- endif -%}>{{ option -}} <!-- Dropdown for select fields -->
</option> <select class="form-control"
{% endfor %} id="{{ attrib.attrib_name }}"
</select> name="{{ attrib.attrib_name }}"
{%- else %} {%- if attrib.required %} required {% endif %}>
<!-- Input field for other inputs --> {% for option in attrib.options -%}
<input id="{{ attrib.attrib_name }}" name="{{ attrib.attrib_name }}" type="{{ attrib.html_input_type }}" <option value="{{ option }}"
{%- if attrib.required %} required {%- endif %} {%- if item and item[attrib.attrib_name] == option %} selected {% endif %}
{%- if attrib.min_val %} min="{{ attrib.min_val }}" {%- endif %} {%- if not item and attrib.default_val is not none and attrib.default_val == option %} selected {% endif %}>
{%- if attrib.max_val %} max="{{ attrib.max_val }}" {%- endif %} {{ option }}
{%- if attrib.step %} step="{{ attrib.step }}" {%- endif %} </option>
{%- if attrib.max_length %} maxlength="{{ attrib.max_length }}" {%- endif %} {% endfor %}
{%- if attrib.min_length %} minlength="{{ attrib.min_length }}" {%- endif %} </select>
{%- if attrib.regex %} pattern="{{ attrib.regex }}" {%- endif %} {%- else %}
{%- if item %} <!-- Input field for other inputs -->
value="{{ item[attrib.attrib_name] }}" <input class="form-control"
{%- else %} id="{{ attrib.attrib_name }}"
{%- if attrib.default_val is not none %} value="{{ attrib.default_val }}" {%- endif %} name="{{ attrib.attrib_name }}"
{%- endif -%} type="{{ attrib.html_input_type }}"
/> {% if attrib.required %} required {% endif %}
{%- endif %} {% if attrib.min_val %} min="{{ attrib.min_val }}" {% endif %}
</p> {% if attrib.max_val %} max="{{ attrib.max_val }}" {% endif %}
{% endfor %} {% if attrib.step %} step="{{ attrib.step }}" {% endif %}
<p><input type="submit" value="{% if item %}Update{% else %}Submit{% endif %}" /></p> {% if attrib.max_length %} maxlength="{{ attrib.max_length }}" {% endif %}
<button type="button" onclick="window.location.href='/'">Cancel</button> {% if attrib.min_length %} minlength="{{ attrib.min_length }}" {% endif %}
</form> {% if attrib.regex %} pattern="{{ attrib.regex }}" {% endif %}
{% if item %} value="{{ item[attrib.attrib_name] }}" {% endif %}
{% if not item and attrib.default_val is not none %} value="{{ attrib.default_val }}" {% endif %}>
{%- endif %}
</div>
</div>
{% endfor %}
</div>
<!-- Sticky action buttons -->
<div class="sticky-actions">
<div class="d-flex justify-content-between">
<button type="button"
onclick="window.location.href='/'"
class="btn btn-outline-secondary px-4">
<i class="bi bi-x-lg me-1"></i>Cancel
</button>
<button type="submit" class="btn btn-primary px-4">
<i class="bi bi-check-lg me-1"></i>
{% if item %}Update{% else %}Submit{% endif %}
</button>
</div>
</div>
</form>
</div>
</div>
</main> </main>
<!-- Bootstrap JS (for dropdowns) -->
<!-- Bootstrap JS -->
<script src="{{ url_for('static', filename='js/bootstrap.bundle.min.js') }}"></script> <script src="{{ url_for('static', filename='js/bootstrap.bundle.min.js') }}"></script>
</body> </body>
</html> </html>