Files
Rendiciones-App/templates/edit_producto.html

86 lines
3.5 KiB
HTML

{% extends "macros/base.html" %}
{% block title %}Editar Producto{% endblock %}
{% block head %}
<!-- HEAD -->
{% endblock %}
{% block content %}
<div class="row justify-content-center">
<div class="col-md-8">
<h2 class="mb-4">Editar Producto</h2>
{% with messages = get_flashed_messages(with_categories=true) %}
{% if messages %}
{% for category, message in messages %}
<div class="alert alert-{{ category }}">{{ message|safe }}</div>
{% endfor %}
{% endif %}
{% endwith %}
<div class="card shadow-sm">
<div class="card-body">
<form method="POST">
<div class="mb-3">
<label class="form-label">Zona</label>
<select class="form-select" name="zona_id" required>
<option value="" disabled>Seleccionar Zona...</option>
{% for zona in zonas %}
<option value="{{ zona[0] }}" {% if zona[0] == producto[1] %}selected{% endif %}>
{{ zona[1] }}
</option>
{% endfor %}
</select>
</div>
<div class="mb-3">
<label class="form-label">Nombre del Producto</label>
<input type="text" class="form-control" name="name" value="{{ producto[2] }}" required>
</div>
<div class="row mb-4">
<div class="col-md-6">
<label class="form-label">Precio de Venta</label>
<div class="input-group">
<span class="input-group-text">$</span>
<input type="text" class="form-control money-input" name="price" value="{{ producto[3]|int }}" required>
</div>
</div>
<div class="col-md-6">
<label class="form-label">Comisión</label>
<div class="input-group">
<span class="input-group-text">$</span>
<input type="text" class="form-control money-input" name="commission" value="{{ producto[4]|int }}" required>
</div>
</div>
</div>
<div class="d-flex justify-content-between">
<a href="{{ url_for('manage_products') }}" class="btn btn-secondary">Cancelar</a>
<button type="submit" class="btn btn-primary">Actualizar Producto</button>
</div>
</form>
</div>
</div>
</div>
</div>
<script>
document.querySelectorAll('.money-input').forEach(function(input) {
input.addEventListener('input', function(e) {
let value = this.value.replace(/\D/g, '');
if (value !== '') {
this.value = parseInt(value, 10).toLocaleString('es-CL');
} else {
this.value = '';
}
});
});
// Artificially trigger the input event on load to format the raw DB numbers
window.addEventListener('DOMContentLoaded', () => {
document.querySelectorAll('.money-input').forEach(input => {
input.dispatchEvent(new Event('input'));
});
});
</script>
{% endblock %}