Jason Howard
Jason Howard

Reputation: 1586

Simulate click on bootstrap-datepicker

I've got a bootstrap datetimepicker element on my page. I'd like to open the calendar on this element without clicking on the input field directly. I've tried everything and can get a click event to open the calendar.

Here is the element:

            <div class="input-group date basedatefield">
                <input type="text" name="basefield" autocomplete="off" readonly="" class="form-control" id="id_basefield" dp_config="{"id": "dp_37", "picker_type": "DATE", "linked_to": null, "options": {"showClose": false, "showClear": true, "showTodayButton": false, "format": "MM/DD/YYYY", "useCurrent": false, "ignoreReadonly": true, "keepInvalid": true}}">
                <div class="input-group-addon input-group-append" data-target="#basedatetimepicker1" data-toggle="datetimepickerv">
                    <div class="input-group-text"><i class="glyphicon glyphicon-calendar"></i></div>
                </div>
            </div>

I've tried these, but they won't simiulate a click and/or open the calendar on this field

    document.getElementById('id_basefield').click();            
    document.getElementsByClassName('basedatefield')[0].click();            
    document.getElementsByClassName('input-group')[0].click();

Upvotes: 0

Views: 215

Answers (1)

yjay
yjay

Reputation: 1023

The library has a show method available:

https://bootstrap-datepicker.readthedocs.io/en/latest/methods.html#show

I think you should do:

$('.datepicker').datepicker('show');

Upvotes: 0

Related Questions