Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How can I show the date picker on input and icon click #704

Closed
isAlmogK opened this issue Dec 16, 2014 · 16 comments
Closed

How can I show the date picker on input and icon click #704

isAlmogK opened this issue Dec 16, 2014 · 16 comments

Comments

@isAlmogK
Copy link

Right now it works just by clicking the icon but I would also like it to show when a user clicks the input flied

@brubie
Copy link

brubie commented Dec 18, 2014

I've solved this doing the following:

<div class="col-md-6 input-group">
    <input type="text" id="testdate" name="testdate" class="form-control" value="">
    <label class="input-group-addon btn" for="testdate">
       <span class="fa fa-calendar"></span>
    </label>                    
</div>

@kingjerod
Copy link

In case anybody else stumbles on this question, this is how I solved it with jQuery:

$('.open-datetimepicker').click(function(event){
    event.preventDefault();
    $('#datetimepicker').click();
});

Your HTML might look similar to this:

<div class="input-group">
    <input type="text" id="datetimepicker" class="form-control" name="date">
    <label class="input-group-addon btn" for="date">
       <span class="fa fa-calendar open-datetimepicker"></span>
    </label>
</div>

@brubie
Copy link

brubie commented Jan 14, 2015

This works for us in both Chrome and Safari. Thanks!

@Eonasdan
Copy link
Owner

Eonasdan commented Feb 3, 2015

You can easily do this:

<div class="form-group">
    <div class="input-group date" id="datetimepicker1">
        <input type="text" class="form-control" /><span class="input-group-addon"><span class="glyphicon-calendar glyphicon"></span></span>
         </div>
</div>

$('#datetimepicker1 input').click(function(event){
   $('#datetimepicker1 ').data("DateTimePicker").show();
});

Also a new feature in the dev branch, you can press the down arrow key while focused on the input box to show the picker

@starter69
Copy link

perhaps binding focus is better than click?

@mkotov13
Copy link

Thanks @brubie!!! that works

@Eonasdan
Copy link
Owner

the current version allows allowInputToggle which will open the picker from either the icon or the textbox

@vietnguyen09
Copy link

Thanks @brubie your solution safe me a headache and hours googling

@DanielFurmanov
Copy link

as @Eonasdan said just use:

    $('#datepicker).datetimepicker({                            
                  allowInputToggle: true
          });

and it works like a charm

@sylvinho81
Copy link

Thanks @brubie .

@santosh-k1
Copy link

santosh-k1 commented Sep 1, 2016

I have used one main wrapper in below solution to use where we can open the date picker on text box as well as glyphicon-calendar ...

<div class="input-group date" id="ReportDate">
                  <div id="txtdatefrom">
                  <input accesskey="r" readonly="true" class="form-control datepicker" placeholder="Select Date" ng-required="true" ng-model="SelectedReportDate" type="text" id="txtReportDate" name="txtReportDate" required="required" data-ng-animate="2">
                  </div>
                  <span class="input-group-addon text-pointer">
                  <span class="glyphicon glyphicon-calendar"></span>
                  </span>
                 </div>

$('#ReportDate').datepicker(
                  {
                      format: 'dd/mm/yyyy',
                      autoclose: true,
                      forceParse: false,
                      Default: true,
                      pickDate: true,
                      todayHighlight: true,

                  });

@techyaura
Copy link

techyaura commented Oct 14, 2016

@kingjerod. Thanks.
Only instead of click, i have used focus.

$('.open-datetimepicker').click(function(event){
    event.preventDefault();
    $('#datetimepicker').focus();
});

@decentplusd
Copy link

Thanks @brubie

kikonen pushed a commit to kikonen/bootstrap-datetimepicker that referenced this issue Jan 2, 2017
Add grammatically correct "No files selected" message
@pancakesFORlunch
Copy link

Thanks @rroxysam you're a life saver 👍

@tarmotalu
Copy link

Use data-provide attribute for input-group div.

 <div class="input-group date" data-provide="datepicker">
  <input type="text">
  <span class="input-group-addon">
    <span class="glyphicon glyphicon-calendar"></span>
  </span>
</div>

@vaniachoi
Copy link

what if i have an icon, and when i pick the date, the value of a span change? not input?

Repository owner locked and limited conversation to collaborators Jun 17, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests