XH_Digital_Management/templates/form_partial.html

173 lines
11 KiB
HTML
Raw Normal View History

2024-06-06 18:02:55 +08:00
{% load tags %}
<form id="addEditForm" method="post">
{% csrf_token %}
2024-06-06 21:27:24 +08:00
{% if form.instance.pk %}
<input type="hidden" name="id" value="{{ form.instance.pk }}">
2024-06-06 18:02:55 +08:00
{% endif %}
<div class="card-body">
<div class="row">
<div class="col-md-6">
{% for field in form %}
{% if forloop.counter0|divisibleby:2 %}
<div class="mb-3">
<label class="form-label" for="{{ field.id_for_label }}">{{ field.label }}</label>
2024-06-06 21:27:24 +08:00
{% if field.field.widget.input_type == "text" %}
<input type="text" class="form-control" id="{{ field.id_for_label }}" name="{{ field.name }}" value="{{ field.value|default_if_none:'' }}" placeholder="{{ field.label }}">
{% elif field.field.widget.input_type == "number" %}
<input type="number" class="form-control" id="{{ field.id_for_label }}" name="{{ field.name }}" value="{{ field.value|default_if_none:'' }}" placeholder="{{ field.label }}">
{% elif field.field.widget.input_type == "select" %}
2024-06-06 18:02:55 +08:00
<select class="form-control" id="{{ field.id_for_label }}" name="{{ field.name }}">
{% for choice in field.field.choices %}
<option value="{{ choice.0 }}" {% if choice.0 == field.value %}selected{% endif %}>{{ choice.1 }}</option>
{% endfor %}
</select>
{% elif field|is_input_type:"textarea" %}
2024-06-06 21:27:24 +08:00
<textarea class="form-control" id="{{ field.id_for_label }}" name="{{ field.name }}" rows="3">{{ field.value|default_if_none:'' }}</textarea>
{% elif field.field.widget.input_type == "date" %}
<input type="date" class="form-control" id="{{ field.id_for_label }}" name="{{ field.name }}" value="{{ field.value|date:"Y-m-d" }}">
{% elif field.field.widget.input_type == "datetime-local" %}
<input type="datetime-local" class="form-control" id="{{ field.id_for_label }}" name="{{ field.name }}" value="{{ field.value|date:"Y-m-d\TH:i" }}">
2024-06-06 21:27:24 +08:00
{% elif field.field.widget.input_type == "email" %}
<input type="email" class="form-control" id="{{ field.id_for_label }}" name="{{ field.name }}" value="{{ field.value|default_if_none:'' }}" placeholder="{{ field.label }}">
{% elif field.field.widget.input_type == "password" %}
2024-06-06 18:02:55 +08:00
<input type="password" class="form-control" id="{{ field.id_for_label }}" name="{{ field.name }}" placeholder="{{ field.label }}">
2024-06-06 21:27:24 +08:00
{% elif field.field.widget.input_type == "checkbox" %}
2024-06-06 18:02:55 +08:00
<div class="form-check">
<input type="checkbox" class="form-check-input" id="{{ field.id_for_label }}" name="{{ field.name }}" {% if field.value %}checked{% endif %}>
<label class="form-check-label" for="{{ field.id_for_label }}">{{ field.label }}</label>
</div>
{% else %}
{{ field }}
{% endif %}
{% if field.help_text %}
<small class="form-text text-muted">{{ field.help_text }}</small>
{% endif %}
{% for error in field.errors %}
<div class="text-danger">{{ error }}</div>
{% endfor %}
</div>
{% endif %}
{% endfor %}
</div>
<div class="col-md-6">
{% for field in form %}
{% if not forloop.counter0|divisibleby:2 %}
<div class="mb-3">
<label class="form-label" for="{{ field.id_for_label }}">{{ field.label }}</label>
2024-06-06 21:27:24 +08:00
{% if field.field.widget.input_type == "text" %}
<input type="text" class="form-control" id="{{ field.id_for_label }}" name="{{ field.name }}" value="{{ field.value|default_if_none:'' }}" placeholder="{{ field.label }}">
{% elif field.field.widget.input_type == "number" %}
<input type="number" class="form-control" id="{{ field.id_for_label }}" name="{{ field.name }}" value="{{ field.value|default_if_none:'' }}" placeholder="{{ field.label }}">
{% elif field.field.widget.input_type == "select" %}
2024-06-06 18:02:55 +08:00
<select class="form-control" id="{{ field.id_for_label }}" name="{{ field.name }}">
{% for choice in field.field.choices %}
<option value="{{ choice.0 }}" {% if choice.0 == field.value %}selected{% endif %}>{{ choice.1 }}</option>
{% endfor %}
</select>
{% elif field|is_input_type:"textarea" %}
2024-06-06 21:27:24 +08:00
<textarea class="form-control" id="{{ field.id_for_label }}" name="{{ field.name }}" rows="3">{{ field.value|default_if_none:'' }}</textarea>
{% elif field.field.widget.input_type == "date" %}
<input type="date" class="form-control" id="{{ field.id_for_label }}" name="{{ field.name }}" value="{{ field.value|date:"Y-m-d" }}">
{% elif field.field.widget.input_type == "datetime-local" %}
<input type="datetime-local" class="form-control" id="{{ field.id_for_label }}" name="{{ field.name }}" value="{{ field.value|date:"Y-m-d\TH:i" }}">
2024-06-07 14:20:58 +08:00
{% elif field.field.widget.input_type == "month" %}
<input type="date" class="form-control" id="{{ field.id_for_label }}" name="{{ field.name }}" value="{{ field.value|date:"Y-m-d" }}">
2024-06-06 21:27:24 +08:00
{% elif field.field.widget.input_type == "email" %}
<input type="email" class="form-control" id="{{ field.id_for_label }}" name="{{ field.name }}" value="{{ field.value|default_if_none:'' }}" placeholder="{{ field.label }}">
{% elif field.field.widget.input_type == "password" %}
2024-06-06 18:02:55 +08:00
<input type="password" class="form-control" id="{{ field.id_for_label }}" name="{{ field.name }}" placeholder="{{ field.label }}">
2024-06-06 21:27:24 +08:00
{% elif field.field.widget.input_type == "checkbox" %}
2024-06-06 18:02:55 +08:00
<div class="form-check">
<input type="checkbox" class="form-check-input" id="{{ field.id_for_label }}" name="{{ field.name }}" {% if field.value %}checked{% endif %}>
<label class="form-check-label" for="{{ field.id_for_label }}">{{ field.label }}</label>
</div>
{% else %}
{{ field }}
{% endif %}
{% if field.help_text %}
<small class="form-text text-muted">{{ field.help_text }}</small>
{% endif %}
{% for error in field.errors %}
<div class="text-danger">{{ error }}</div>
{% endfor %}
</div>
{% endif %}
{% endfor %}
</div>
</div>
</div>
2024-06-06 21:27:24 +08:00
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">取消</button>
<button type="submit" class="btn btn-primary" id="submitForm">保存</button>
</div>
2024-06-06 18:02:55 +08:00
</form>
<script type="text/javascript">
$(document).ready(function () {
2024-06-19 02:03:59 +08:00
function updateSecondaryDepartments(primaryDepartment, selectedSecondaryDepartment = null) {
var url = "{% url 'load_secondary_departments' %}";
$.ajax({
url: url,
data: {
2024-06-19 02:03:59 +08:00
'primary_department': primaryDepartment
},
2024-06-19 02:03:59 +08:00
success: function (html) {
$('#id_secondary_department').html(html);
if (selectedSecondaryDepartment) {
$('#id_secondary_department').val(selectedSecondaryDepartment);
}
}
});
}
$('#id_primary_department').change(function () {
2024-06-19 02:03:59 +08:00
var primaryDepartment = $(this).val();
if (primaryDepartment) {
updateSecondaryDepartments(primaryDepartment);
} else {
$('#id_secondary_department').html('<option value="">---------</option>');
}
});
// 如果在页面加载时已选择一级部门,则加载相应的二级部门
2024-06-19 02:03:59 +08:00
var initialPrimaryDepartment = $('#id_primary_department').val();
var initialSecondaryDepartment = $('#id_secondary_department').val();
2024-06-19 02:03:59 +08:00
if (initialPrimaryDepartment) {
updateSecondaryDepartments(initialPrimaryDepartment, initialSecondaryDepartment);
}
2024-06-19 02:03:59 +08:00
2024-06-16 19:34:15 +08:00
// 动态生成id_seal_type的select选项
var sealTypeOptions = [
{ value: '公章', text: '公章' },
{ value: '法人章', text: '法人章' },
{ value: '合同章', text: '合同章' },
{ value: '财务章', text: '财务章' },
{ value: '其他', text: '其他' }
];
var $sealTypeSelect = $('<select>', {
class: 'form-control',
id: 'id_seal_type',
name: 'seal_type'
});
$.each(sealTypeOptions, function (index, option) {
$sealTypeSelect.append($('<option>', {
value: option.value,
text: option.text
}));
});
// 替换现有的#id_seal_type元素
$('#id_seal_type').replaceWith($sealTypeSelect);
// 如果需要在选择时执行某些操作,可以添加监听器
$('#id_seal_type').change(function() {
var selectedSealType = $(this).val();
console.log('选择的用印类型是:' + selectedSealType);
// 在这里添加其他需要的处理逻辑
});
2024-06-19 02:03:59 +08:00
2024-06-16 19:34:15 +08:00
});
</script>