I try to use the DatePicker
tool from link in my project Django
I wish that the date entered by the user was sent with method POST
in my view, the problem is that I do not know anything about javascript
and this is what I have in my HTML
<script type="text/javascript">
$(function() {
$('input[name="daterange"]').daterangepicker({
locale: {
format: 'DD/MM/YYYY '
},
ranges: {
'Hoy': [moment(), moment()],
'Ayer': [moment().subtract(1, 'days'), moment().subtract(1, 'days')],
'Ultimos 7 dias': [moment().subtract(6, 'days'), moment()],
'Ultimos 30 dias': [moment().subtract(29, 'days'), moment()],
'Este Mes': [moment().startOf('month'), moment().endOf('month')],
'Mes pasado': [moment().subtract(1, 'month').startOf('month'), moment().subtract(1, 'month').endOf('month')]
}
});
$(window).scroll(function() {
if ($('input[name="daterange"]').length) {
$('input[name="daterange"]').daterangepicker("close");
}
});
});
</script>
<form action="{% url 'subestados' %}" method="post">
<div class="col-md-3 mb-3">
<label>Rango: </label>
<input type="text" name="daterange" class="form-control"/>
</div>
</form>
I understand that there is a way with AJAX
to send with post
method with a code similar to this:
function(start, end, label) {
$.post("url",
{
"start":start,
"end": end
},
function(data, status){
alert("Data sent);
});
}
But I do not know how to implement it. Any ideas?