2

I working with a dashboard project, it has a dashboard and it does build a query based on the days selected from the day picker, currently I was able to implement the date picker with Flask DateField form and it does work as expected.

class ExampleForm(Form):
    dt = DateField('DatePicker', format='%Y-%m-%d')
    dt2 = DateField('DatePicker', format='%Y-%m-%d')


<form action="" method="POST">
    {{ form.hidden_tag() }}
   <a> Start Date {{ form.dt(class_='datepicker') }}</a>
   <a> End Date {{ form.dt2(class_='datepicker') }}</a>
<button class="w3-button w3-round-xlarge w3-teal w3-small w3-border " type="submit" value="submit"><b>Submit</b></button>
</form>

I would like to implement a more friendly solution like this one, https://www.daterangepicker.com/#example4 , where I can select multiple options or a date range.

Can this be achieved thru flask_wtf ?

I was looking for an answer in other questions but no success yet

<script type="text/javascript" src="https://cdn.jsdelivr.net/jquery/latest/jquery.min.js"></script>
<script type="text/javascript" src="https://cdn.jsdelivr.net/momentjs/latest/moment.min.js"></script>
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/daterangepicker/daterangepicker.min.js"></script>
<link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/npm/daterangepicker/daterangepicker.css" />

<form method="GET">
        <input type="hidden" id="start" name="startDate">
        <input type="hidden" id="end" name="endDate">
<div id="reportrange" style="background: #fff; cursor: pointer; padding: 5px 10px; border: 1px solid #ccc; width: 100%">
    <i class="fa fa-calendar"></i>&nbsp;
    <span></span> <i class="fa fa-caret-down"></i>
</div>
<input type="submit">

<script type="text/javascript">
    $(function () {

        var start = moment().subtract(29, 'days');
        var end = moment();

        function cb(start, end) {
            $('#reportrange span').html(start.format('MMMM D, YYYY') + ' - ' + end.format('MMMM D, YYYY'));
        }

        $('#reportrange').daterangepicker({
            startDate: start,
            endDate: end,
            ranges: {
                'Today': [moment(), moment()],
                'Yesterday': [moment().subtract(1, 'days'), moment().subtract(1, 'days')],
                'Last 7 Days': [moment().subtract(6, 'days'), moment()],
                'Last 30 Days': [moment().subtract(29, 'days'), moment()],
                'This Month': [moment().startOf('month'), moment().endOf('month')],
                'Last Month': [moment().subtract(1, 'month').startOf('month'), moment().subtract(1, 'month').endOf('month')]
            }
        }, cb);

        cb(start, end);

    });
</script>
</form>  

I cant return the selected values to my flask function.

any guide or help will be much appreciated

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.